From 1fe44198b88fb7f71fa6d8e2ca8ed6a770662968 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 15 Feb 2025 23:53:46 +0400 Subject: [PATCH 01/18] 13 -- Add registration page --- .vscode/launch.json | 22 ++++++++++ .../fc/config/SecurityConfiguration.java | 3 +- .../fc/user/controller/UserController.java | 42 +++++++++++++++++++ .../java/ru/ulstu/fc/user/model/User.java | 6 +++ .../java/ru/ulstu/fc/user/model/UserDto.java | 40 ++++++++++++++++++ src/main/resources/templates/register.html | 27 ++++++++++++ 6 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 src/main/java/ru/ulstu/fc/user/controller/UserController.java create mode 100644 src/main/java/ru/ulstu/fc/user/model/UserDto.java create mode 100644 src/main/resources/templates/register.html diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..27d7d9d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + + { + "type": "java", + "name": "Current File", + "request": "launch", + "mainClass": "${file}" + }, + { + "type": "java", + "name": "FuzzyControllerApplication", + "request": "launch", + "mainClass": "ru.ulstu.fc.FuzzyControllerApplication", + "projectName": "fuzzy-controller" + } + ] +} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/fc/config/SecurityConfiguration.java b/src/main/java/ru/ulstu/fc/config/SecurityConfiguration.java index 6583cd0..7547aaa 100644 --- a/src/main/java/ru/ulstu/fc/config/SecurityConfiguration.java +++ b/src/main/java/ru/ulstu/fc/config/SecurityConfiguration.java @@ -14,11 +14,10 @@ import ru.ulstu.fc.user.model.UserRoleConstants; @Configuration @EnableWebSecurity -@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) public class SecurityConfiguration { private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class); private final String[] permittedUrls = new String[]{ - "/login", "/index", + "/login", "/index", "/user/register", "/public/**", "/organizers", "/webjars/**", "/h2-console/*", "/h2-console", "/css/**", "/js/**", "/img/**", diff --git a/src/main/java/ru/ulstu/fc/user/controller/UserController.java b/src/main/java/ru/ulstu/fc/user/controller/UserController.java new file mode 100644 index 0000000..97fe0d6 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/user/controller/UserController.java @@ -0,0 +1,42 @@ +package ru.ulstu.fc.user.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.Errors; +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 org.springframework.web.servlet.ModelAndView; + +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; + +@Controller +public class UserController { + private final UserService userService; + + public UserController(UserService userService) { + this.userService = userService; + } + + @GetMapping("/user/register") + public String showRegistrationForm(WebRequest request, Model model) { + UserDto userDto = new UserDto(); + model.addAttribute("user", userDto); + return "register"; + } + + @PostMapping("/user/register") + public String registerUserAccount( + @ModelAttribute("user") @Valid UserDto userDto, + HttpServletRequest request, + Errors errors) { + + userService.createUser(new User(userDto)); + return "redirect:/login"; + } +} 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 11b3162..1c81271 100644 --- a/src/main/java/ru/ulstu/fc/user/model/User.java +++ b/src/main/java/ru/ulstu/fc/user/model/User.java @@ -6,6 +6,7 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; import jakarta.persistence.Table; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; @@ -46,6 +47,11 @@ public class User extends BaseEntity { this.roles = roles; } + public User(UserDto userDto) { + this.login = userDto.getLogin(); + this.password = userDto.getPassword(); + } + public String getLogin() { return login; } diff --git a/src/main/java/ru/ulstu/fc/user/model/UserDto.java b/src/main/java/ru/ulstu/fc/user/model/UserDto.java new file mode 100644 index 0000000..0a7e064 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/user/model/UserDto.java @@ -0,0 +1,40 @@ +package ru.ulstu.fc.user.model; + +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; + +public class UserDto { + @NotNull + @NotEmpty + private String login; + + @NotNull + @NotEmpty + private String password; + private String matchingPassword; + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getMatchingPassword() { + return matchingPassword; + } + + public void setMatchingPassword(String matchingPassword) { + this.matchingPassword = matchingPassword; + } + +} diff --git a/src/main/resources/templates/register.html b/src/main/resources/templates/register.html new file mode 100644 index 0000000..a56d912 --- /dev/null +++ b/src/main/resources/templates/register.html @@ -0,0 +1,27 @@ + + +
+

form

+
+
+ + +

Validation error

+
+
+ + +

Validation error

+
+
+ + +
+ +
+ + login +
+ + + \ No newline at end of file From 9cdc2b86b4320e1b37cc37ddde10f972a5692990 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 16 Feb 2025 14:48:29 +0400 Subject: [PATCH 02/18] #13 -- Add gitea actions --- .../templates/.gitea/workflows/test.yaml | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/resources/templates/.gitea/workflows/test.yaml diff --git a/src/main/resources/templates/.gitea/workflows/test.yaml b/src/main/resources/templates/.gitea/workflows/test.yaml new file mode 100644 index 0000000..0c6a5fc --- /dev/null +++ b/src/main/resources/templates/.gitea/workflows/test.yaml @@ -0,0 +1,20 @@ +name: Test fuzzy controller +run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 +on: [push] + +jobs: + Explore-Gitea-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" + - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ gitea.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." + - run: ./gradlew test \ No newline at end of file From 8f58bec32a571afe0f37e2d7423228dda613e4ce Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 16 Feb 2025 14:54:13 +0400 Subject: [PATCH 03/18] #13 --Move config --- .../resources/templates/.gitea => .gitea}/workflows/test.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {src/main/resources/templates/.gitea => .gitea}/workflows/test.yaml (100%) diff --git a/src/main/resources/templates/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml similarity index 100% rename from src/main/resources/templates/.gitea/workflows/test.yaml rename to .gitea/workflows/test.yaml From 938bc36347b8907c5f1b0d88189bb4a4e33f3e25 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 16 Feb 2025 14:55:47 +0400 Subject: [PATCH 04/18] #13 -- Fix config --- .gitea/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index 0c6a5fc..2a5104e 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -17,4 +17,4 @@ jobs: run: | ls ${{ gitea.workspace }} - run: echo "🍏 This job's status is ${{ job.status }}." - - run: ./gradlew test \ No newline at end of file + - run: bash gradlew test \ No newline at end of file From 505a05bd0cc4049fdd550799366d8a11ef3b8731 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 16 Feb 2025 15:02:57 +0400 Subject: [PATCH 05/18] #13 -- Try other image --- .gitea/workflows/test.yaml | 2 ++ .gitignore | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index 2a5104e..18f2948 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -5,6 +5,8 @@ on: [push] jobs: Explore-Gitea-Actions: runs-on: ubuntu-latest + container: + image: "exoplatform/jdk:openjdk-21-ubuntu-2204" steps: - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" diff --git a/.gitignore b/.gitignore index b1933c3..e920055 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ # Created by https://www.toptal.com/developers/gitignore/api/intellij,java,maven,gradle,eclipse,netbeans,node # Edit at https://www.toptal.com/developers/gitignore?templates=intellij,java,maven,gradle,eclipse,netbeans,node +data/* + ### Eclipse ### .metadata bin/ From 3abe71b07dea054df9dda51874be26ea1652ff03 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 16 Feb 2025 15:05:46 +0400 Subject: [PATCH 06/18] #13 -- Fix config --- .gitea/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index 18f2948..8e4cc2b 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -5,7 +5,7 @@ on: [push] jobs: Explore-Gitea-Actions: runs-on: ubuntu-latest - container: + container: image: "exoplatform/jdk:openjdk-21-ubuntu-2204" steps: - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." From e40bde48300c193f0fdf1a191aa110313accfdb9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 16 Feb 2025 15:36:19 +0400 Subject: [PATCH 07/18] #13 -- Fix ci --- .gitea/workflows/test.yaml | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index 8e4cc2b..f95e4cd 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -1,22 +1,19 @@ -name: Test fuzzy controller -run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 -on: [push] - +name: CI fuzzy controller +on: + push: + branches: [ master ] jobs: - Explore-Gitea-Actions: + container-test-job: runs-on: ubuntu-latest container: - image: "exoplatform/jdk:openjdk-21-ubuntu-2204" + image: exoplatform/jdk:openjdk-21-ubuntu-2204 + env: + NODE_ENV: development + ports: + - 80 + volumes: + - my_docker_volume:/volume_mount + options: --cpus 1 steps: - - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" - - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ gitea.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." - - run: bash gradlew test \ No newline at end of file + - name: Test fuzzy controller + run: bash gradlew test \ No newline at end of file From dde1bfec7b1ec5afcafb15d84b5185f22d607aed Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 16 Feb 2025 21:30:43 +0400 Subject: [PATCH 08/18] #13 -- Fix ci --- .gitea/workflows/test.yaml | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index f95e4cd..cbd3290 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -1,19 +1,15 @@ name: CI fuzzy controller -on: - push: - branches: [ master ] +on: [push] jobs: container-test-job: runs-on: ubuntu-latest - container: - image: exoplatform/jdk:openjdk-21-ubuntu-2204 - env: - NODE_ENV: development - ports: - - 80 - volumes: - - my_docker_volume:/volume_mount - options: --cpus 1 steps: - - name: Test fuzzy controller - run: bash gradlew test \ No newline at end of file + - uses: actions/checkout@v4 + - name: Set up JDK 21 for x64 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + architecture: x64 + - name: Test with Gradle + run: bash ./gradlew test \ No newline at end of file From 2ca47e0d98c31c4926231d0fcb3fc9a62b1e6db6 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 16 Feb 2025 22:01:51 +0400 Subject: [PATCH 09/18] #13 -- Add proejct rules list --- .vscode/launch.json | 10 ----- src/main/resources/templates/listRules.html | 42 ------------------- src/main/resources/templates/loginError.html | 11 +++-- .../resources/templates/project/edit.html | 33 +++++++++++++++ .../resources/templates/project/list.html | 2 +- .../templates/project/listRules.html | 30 +++++++++++++ 6 files changed, 69 insertions(+), 59 deletions(-) delete mode 100644 src/main/resources/templates/listRules.html create mode 100644 src/main/resources/templates/project/listRules.html diff --git a/.vscode/launch.json b/.vscode/launch.json index 27d7d9d..9cad71a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,16 +1,6 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ - - { - "type": "java", - "name": "Current File", - "request": "launch", - "mainClass": "${file}" - }, { "type": "java", "name": "FuzzyControllerApplication", diff --git a/src/main/resources/templates/listRules.html b/src/main/resources/templates/listRules.html deleted file mode 100644 index 2b93617..0000000 --- a/src/main/resources/templates/listRules.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - Список правил - - -
- - - - - - - - - - - - - - - - - - - - -
Правила
Еслиито - - - - - - - -
- Добавить правило -
- diff --git a/src/main/resources/templates/loginError.html b/src/main/resources/templates/loginError.html index 1d08df3..7decca6 100644 --- a/src/main/resources/templates/loginError.html +++ b/src/main/resources/templates/loginError.html @@ -6,12 +6,11 @@ - +
diff --git a/src/main/resources/templates/project/list.html b/src/main/resources/templates/project/list.html index 69e049c..e5f6165 100644 --- a/src/main/resources/templates/project/list.html +++ b/src/main/resources/templates/project/list.html @@ -3,7 +3,7 @@ xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml" layout:decorate="~{default}"> - Список правил + Список проектов
diff --git a/src/main/resources/templates/project/listRules.html b/src/main/resources/templates/project/listRules.html new file mode 100644 index 0000000..52331ad --- /dev/null +++ b/src/main/resources/templates/project/listRules.html @@ -0,0 +1,30 @@ + + + + + Список правил + + +
+

Список правил

+
+
+ 1. Если +
+
+ Переменная +
+
+ есть +
+
+ значение +
+
+ И / ИЛИ +
+
+
+ + \ No newline at end of file From ef9b78251c75d802dc53d43cee29f233e8f9f28b Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 17 Feb 2025 10:44:14 +0400 Subject: [PATCH 10/18] #13 -- Show rules of project --- .../controller/ProjecRulesController.java | 23 +++++++++++++++++++ .../project/controller/ProjectController.java | 10 ++++++-- .../fc/project/repository/RuleRepository.java | 12 ++++++++++ .../project/service/ProjectRulesService.java | 21 +++++++++++++++++ .../java/ru/ulstu/fc/rule/model/Rule.java | 20 ++++++++++++++++ .../resources/templates/project/edit.html | 4 ++-- 6 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ru/ulstu/fc/project/controller/ProjecRulesController.java create mode 100644 src/main/java/ru/ulstu/fc/project/repository/RuleRepository.java create mode 100644 src/main/java/ru/ulstu/fc/project/service/ProjectRulesService.java create mode 100644 src/main/java/ru/ulstu/fc/rule/model/Rule.java diff --git a/src/main/java/ru/ulstu/fc/project/controller/ProjecRulesController.java b/src/main/java/ru/ulstu/fc/project/controller/ProjecRulesController.java new file mode 100644 index 0000000..be60f8b --- /dev/null +++ b/src/main/java/ru/ulstu/fc/project/controller/ProjecRulesController.java @@ -0,0 +1,23 @@ +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.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import ru.ulstu.fc.project.model.Project; +import ru.ulstu.fc.project.model.ProjectForm; +import ru.ulstu.fc.project.service.ProjectRulesService; +import ru.ulstu.fc.project.service.ProjectService; +import ru.ulstu.fc.user.model.UserRoleConstants; + +@Controller +@Hidden +@RequestMapping("projectRules") +@Secured({UserRoleConstants.ADMIN}) +public class ProjecRulesController { + +} 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 85c28a8..a835938 100644 --- a/src/main/java/ru/ulstu/fc/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/fc/project/controller/ProjectController.java @@ -10,18 +10,22 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import ru.ulstu.fc.project.model.Project; import ru.ulstu.fc.project.model.ProjectForm; +import ru.ulstu.fc.project.service.ProjectRulesService; import ru.ulstu.fc.project.service.ProjectService; 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; - public ProjectController(ProjectService projectService) { + public ProjectController(ProjectService projectService, + ProjectRulesService projectRulesService) { this.projectService = projectService; + this.projectRulesService = projectRulesService; } @GetMapping("list") @@ -36,6 +40,8 @@ public class ProjectController { new ProjectForm((id != null && id != 0) ? projectService.getById(id) : new Project())); + + model.addAttribute("rules", projectRulesService.getByProjectId(id)); return "project/edit"; } diff --git a/src/main/java/ru/ulstu/fc/project/repository/RuleRepository.java b/src/main/java/ru/ulstu/fc/project/repository/RuleRepository.java new file mode 100644 index 0000000..6369ff5 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/project/repository/RuleRepository.java @@ -0,0 +1,12 @@ +package ru.ulstu.fc.project.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; + +import ru.ulstu.fc.rule.model.Rule; + +public interface RuleRepository extends JpaRepository { + + List findByProjectId(Integer projectId); +} diff --git a/src/main/java/ru/ulstu/fc/project/service/ProjectRulesService.java b/src/main/java/ru/ulstu/fc/project/service/ProjectRulesService.java new file mode 100644 index 0000000..5d00690 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/project/service/ProjectRulesService.java @@ -0,0 +1,21 @@ +package ru.ulstu.fc.project.service; + +import java.util.List; + +import org.springframework.stereotype.Service; + +import ru.ulstu.fc.project.repository.RuleRepository; +import ru.ulstu.fc.rule.model.Rule; + +@Service +public class ProjectRulesService { + private final RuleRepository ruleRepository; + + public ProjectRulesService(RuleRepository ruleRepository) { + this.ruleRepository = ruleRepository; + } + + public List getByProjectId(Integer projectId) { + return ruleRepository.findByProjectId(projectId); + } +} diff --git a/src/main/java/ru/ulstu/fc/rule/model/Rule.java b/src/main/java/ru/ulstu/fc/rule/model/Rule.java new file mode 100644 index 0000000..8c5a181 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/model/Rule.java @@ -0,0 +1,20 @@ +package ru.ulstu.fc.rule.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.ManyToOne; +import ru.ulstu.fc.core.model.BaseEntity; +import ru.ulstu.fc.project.model.Project; + +@Entity +public class Rule extends BaseEntity { + @ManyToOne + private Project project; + + public Project getProject() { + return project; + } + + public void setProject(Project project) { + this.project = project; + } +} diff --git a/src/main/resources/templates/project/edit.html b/src/main/resources/templates/project/edit.html index d44a5b4..aa796e0 100644 --- a/src/main/resources/templates/project/edit.html +++ b/src/main/resources/templates/project/edit.html @@ -38,9 +38,9 @@

Список правил

-
+
- 1. Если +
Переменная From 9666419ed2e6775c72e3560abda95bdd389cb1e7 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 17 Feb 2025 12:09:24 +0400 Subject: [PATCH 11/18] #13 -- Fix rule models --- .../controller/InferenceMvcController.java | 39 +++++++++++-------- .../ru/ulstu/fc/rule/model/Antecedent.java | 26 +++++++++---- .../ru/ulstu/fc/rule/model/Consequent.java | 29 ++++++++++++++ .../ru/ulstu/fc/rule/model/InferenceForm.java | 20 +++++----- .../java/ru/ulstu/fc/rule/model/Rule.java | 26 ++++++++++++- .../java/ru/ulstu/fc/rule/model/Variable.java | 15 ++++++- .../ru/ulstu/fc/rule/model/VariableValue.java | 6 ++- src/main/resources/templates/index.html | 16 ++++---- 8 files changed, 130 insertions(+), 47 deletions(-) create mode 100644 src/main/java/ru/ulstu/fc/rule/model/Consequent.java 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 0e9abef..ebd0f13 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/InferenceMvcController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/InferenceMvcController.java @@ -9,6 +9,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import ru.ulstu.fc.rule.model.Antecedent; import ru.ulstu.fc.rule.model.InferenceForm; +import ru.ulstu.fc.rule.model.Variable; +import ru.ulstu.fc.rule.model.VariableValue; import ru.ulstu.fc.rule.service.FuzzyInferenceService; import java.util.Arrays; @@ -26,35 +28,38 @@ public class InferenceMvcController { @GetMapping("/") public String initInference(Model model) { - model.addAttribute("ageAntecedents", getAgeAntecedents()); - model.addAttribute("incomeAntecedents", getIncomeAntecedents()); + model.addAttribute("ageValues", getAgeValues()); + model.addAttribute("incomeValues", getIncomeValues()); model.addAttribute("inferenceForm", new InferenceForm()); return "index"; } @RequestMapping(value = "get-inference", method = RequestMethod.POST) public String getInference(@ModelAttribute InferenceForm inferenceForm, Model model) { - model.addAttribute("ageAntecedents", getAgeAntecedents()); - model.addAttribute("incomeAntecedents", getIncomeAntecedents()); + model.addAttribute("ageValues", getAgeValues()); + model.addAttribute("incomeValues", getIncomeValues()); model.addAttribute("inferenceForm", inferenceForm); model.addAttribute("response", fuzzyInferenceService.getFuzzyInference( - Map.of("возраст", Double.valueOf(inferenceForm.getAgeAntecedent()), - "доход", Double.valueOf(inferenceForm.getIncomeAntecedent()) - ))); + Map.of("возраст", Double.valueOf(inferenceForm.getAgeValue()), + "доход", Double.valueOf(inferenceForm.getIncomeValue())))); return "index"; } - private List getAgeAntecedents() { - return Arrays.asList( - new Antecedent("молодой", "30"), - new Antecedent("средний", "45"), - new Antecedent("старый", "60")); + private List getAgeValues() { + Variable var = new Variable("Age"); + var.getValues().addAll(Arrays.asList( + new VariableValue("молодой", 30.0), + new VariableValue("средний", 45.0), + new VariableValue("старый", 60.0))); + return var.getValues(); } - private List getIncomeAntecedents() { - return Arrays.asList( - new Antecedent("небольшой", "20000"), - new Antecedent("средний", "90000"), - new Antecedent("высокий", "200000")); + private List getIncomeValues() { + Variable var = new Variable("Income"); + var.getValues().addAll(Arrays.asList( + new VariableValue("небольшой", 20000.0), + new VariableValue("средний", 90000.0), + new VariableValue("высокий", 200000.0))); + return var.getValues(); } } diff --git a/src/main/java/ru/ulstu/fc/rule/model/Antecedent.java b/src/main/java/ru/ulstu/fc/rule/model/Antecedent.java index 54915e1..6950aa1 100644 --- a/src/main/java/ru/ulstu/fc/rule/model/Antecedent.java +++ b/src/main/java/ru/ulstu/fc/rule/model/Antecedent.java @@ -1,19 +1,29 @@ package ru.ulstu.fc.rule.model; -public class Antecedent { - private String value; - private String description; +import jakarta.persistence.Entity; +import jakarta.persistence.ManyToOne; +import ru.ulstu.fc.core.model.BaseEntity; - public Antecedent(String description, String value) { - this.description = description; - this.value = value; +@Entity +public class Antecedent extends BaseEntity { + @ManyToOne + private Variable variable; + private String value; + + public Variable getVariable() { + return variable; + } + + public void setVariable(Variable variable) { + this.variable = variable; } public String getValue() { return value; } - public String getDescription() { - return description; + public void setValue(String value) { + this.value = value; } + } diff --git a/src/main/java/ru/ulstu/fc/rule/model/Consequent.java b/src/main/java/ru/ulstu/fc/rule/model/Consequent.java new file mode 100644 index 0000000..ae4148c --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/model/Consequent.java @@ -0,0 +1,29 @@ +package ru.ulstu.fc.rule.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.ManyToOne; +import ru.ulstu.fc.core.model.BaseEntity; + +@Entity +public class Consequent extends BaseEntity { + @ManyToOne + private Variable variable; + private String value; + + public Variable getVariable() { + return variable; + } + + public void setVariable(Variable variable) { + this.variable = variable; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/src/main/java/ru/ulstu/fc/rule/model/InferenceForm.java b/src/main/java/ru/ulstu/fc/rule/model/InferenceForm.java index d336986..7a8ac7e 100644 --- a/src/main/java/ru/ulstu/fc/rule/model/InferenceForm.java +++ b/src/main/java/ru/ulstu/fc/rule/model/InferenceForm.java @@ -1,22 +1,22 @@ package ru.ulstu.fc.rule.model; public class InferenceForm { - private String ageAntecedent; - private String incomeAntecedent; + private String ageValue; + private String incomeValue; - public String getAgeAntecedent() { - return ageAntecedent; + public String getAgeValue() { + return ageValue; } - public void setAgeAntecedent(String ageAntecedent) { - this.ageAntecedent = ageAntecedent; + public void setAgeValue(String ageAntecedent) { + this.ageValue = ageAntecedent; } - public String getIncomeAntecedent() { - return incomeAntecedent; + public String getIncomeValue() { + return incomeValue; } - public void setIncomeAntecedent(String incomeAntecedent) { - this.incomeAntecedent = incomeAntecedent; + public void setIncomeValue(String incomeAntecedent) { + this.incomeValue = incomeAntecedent; } } diff --git a/src/main/java/ru/ulstu/fc/rule/model/Rule.java b/src/main/java/ru/ulstu/fc/rule/model/Rule.java index 8c5a181..2d929c6 100644 --- a/src/main/java/ru/ulstu/fc/rule/model/Rule.java +++ b/src/main/java/ru/ulstu/fc/rule/model/Rule.java @@ -1,7 +1,10 @@ package ru.ulstu.fc.rule.model; +import java.util.List; + import jakarta.persistence.Entity; import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; import ru.ulstu.fc.core.model.BaseEntity; import ru.ulstu.fc.project.model.Project; @@ -9,6 +12,10 @@ import ru.ulstu.fc.project.model.Project; public class Rule extends BaseEntity { @ManyToOne private Project project; + @OneToMany + private List antecedents; //TODO: AND / OR? + @ManyToOne + private Consequent consequent; public Project getProject() { return project; @@ -16,5 +23,22 @@ public class Rule extends BaseEntity { public void setProject(Project project) { this.project = project; - } + } + + public List getAntecedents() { + return antecedents; + } + + public void setAntecedents(List antecedents) { + this.antecedents = antecedents; + } + + public Consequent getConsequent() { + return consequent; + } + + public void setConsequent(Consequent consequent) { + this.consequent = consequent; + } + } 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 ebbc115..57c07a6 100644 --- a/src/main/java/ru/ulstu/fc/rule/model/Variable.java +++ b/src/main/java/ru/ulstu/fc/rule/model/Variable.java @@ -1,10 +1,17 @@ package ru.ulstu.fc.rule.model; +import java.util.ArrayList; import java.util.List; -public class Variable { +import jakarta.persistence.Entity; +import jakarta.persistence.OneToMany; +import ru.ulstu.fc.core.model.BaseEntity; + +@Entity +public class Variable extends BaseEntity { private String name; - private List values; + @OneToMany + private List values = new ArrayList<>(); public Variable() { } @@ -14,6 +21,10 @@ public class Variable { this.values = values; } + public Variable(String name) { + this.name = name; + } + public String getName() { return name; } diff --git a/src/main/java/ru/ulstu/fc/rule/model/VariableValue.java b/src/main/java/ru/ulstu/fc/rule/model/VariableValue.java index 9bc9550..e3d4fe4 100644 --- a/src/main/java/ru/ulstu/fc/rule/model/VariableValue.java +++ b/src/main/java/ru/ulstu/fc/rule/model/VariableValue.java @@ -1,6 +1,10 @@ package ru.ulstu.fc.rule.model; -public class VariableValue { +import jakarta.persistence.Entity; +import ru.ulstu.fc.core.model.BaseEntity; + +@Entity +public class VariableValue extends BaseEntity { private String fuzzyTerm; private Double value; diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index fbeb483..9ac57fb 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -25,11 +25,11 @@
@@ -40,11 +40,11 @@
From be3f70f14c9b5817a2689d5506287b775970283c Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 17 Feb 2025 13:18:04 +0400 Subject: [PATCH 12/18] xfgdfgf --- .../controller/ProjecRulesController.java | 23 --------- .../fc/rule/controller/RuleController.java | 47 +++++++++++++++++++ .../ulstu/fc/rule/controller/RuleService.java | 5 ++ .../java/ru/ulstu/fc/rule/model/RuleForm.java | 10 ++++ 4 files changed, 62 insertions(+), 23 deletions(-) delete mode 100644 src/main/java/ru/ulstu/fc/project/controller/ProjecRulesController.java create mode 100644 src/main/java/ru/ulstu/fc/rule/controller/RuleController.java create mode 100644 src/main/java/ru/ulstu/fc/rule/controller/RuleService.java create mode 100644 src/main/java/ru/ulstu/fc/rule/model/RuleForm.java diff --git a/src/main/java/ru/ulstu/fc/project/controller/ProjecRulesController.java b/src/main/java/ru/ulstu/fc/project/controller/ProjecRulesController.java deleted file mode 100644 index be60f8b..0000000 --- a/src/main/java/ru/ulstu/fc/project/controller/ProjecRulesController.java +++ /dev/null @@ -1,23 +0,0 @@ -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.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import ru.ulstu.fc.project.model.Project; -import ru.ulstu.fc.project.model.ProjectForm; -import ru.ulstu.fc.project.service.ProjectRulesService; -import ru.ulstu.fc.project.service.ProjectService; -import ru.ulstu.fc.user.model.UserRoleConstants; - -@Controller -@Hidden -@RequestMapping("projectRules") -@Secured({UserRoleConstants.ADMIN}) -public class ProjecRulesController { - -} diff --git a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java new file mode 100644 index 0000000..12906db --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java @@ -0,0 +1,47 @@ +package ru.ulstu.fc.rule.controller; + +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.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +import ru.ulstu.fc.project.model.Project; +import ru.ulstu.fc.project.model.ProjectForm; +import ru.ulstu.fc.rule.model.Rule; +import ru.ulstu.fc.rule.model.RuleForm; + +@Controller +@RequestMapping("rule") +public class RuleController { + private final RuleService ruleService; + + public RuleController(RuleService ruleService) { + this.ruleService = ruleService; + } + + @GetMapping("/edit/{ruleId}") + public String edit(@PathVariable(value = "ruleId") Integer id, Model model) { + model.addAttribute("rule", + new RuleForm((id != null && id != 0) + ? ruleService.getById(id) + : new Rule())); + + return "rule/edit"; + } + + @PostMapping(value = "save", params = "save") + public String save(RuleForm ruleForm, Model model) { + model.addAttribute("rule", ruleService.save(ruleForm)); + return "redirect:/project/edit/"+ruleForm.getProjectId(); + } + + @PostMapping(value = "save", params = "delete") + public String delete(RuleForm ruleForm) { + if (ruleForm != null && ruleForm.getId() != null) { + ruleService.delete(ruleForm); + } + return "redirect:/project/edit/"+ruleForm.getProjectId(); + } +} diff --git a/src/main/java/ru/ulstu/fc/rule/controller/RuleService.java b/src/main/java/ru/ulstu/fc/rule/controller/RuleService.java new file mode 100644 index 0000000..a4df3c9 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/controller/RuleService.java @@ -0,0 +1,5 @@ +package ru.ulstu.fc.rule.controller; + +public class RuleService { + +} diff --git a/src/main/java/ru/ulstu/fc/rule/model/RuleForm.java b/src/main/java/ru/ulstu/fc/rule/model/RuleForm.java new file mode 100644 index 0000000..0f774a9 --- /dev/null +++ b/src/main/java/ru/ulstu/fc/rule/model/RuleForm.java @@ -0,0 +1,10 @@ +package ru.ulstu.fc.rule.model; + +public class RuleForm { + private final Integer projectId; + + public Integer getProjectId() { + return projectId; + } + +} From 495b04e51d1d673859172942fd765c36768c28e2 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 17 Feb 2025 14:08:58 +0400 Subject: [PATCH 13/18] #13 -- Add rule crud --- .vscode/settings.json | 3 ++ .../fc/rule/controller/RuleController.java | 3 +- .../ulstu/fc/rule/controller/RuleService.java | 40 ++++++++++++++++++- .../ru/ulstu/fc/rule/model/Antecedent.java | 4 -- .../java/ru/ulstu/fc/rule/model/Rule.java | 3 ++ .../java/ru/ulstu/fc/rule/model/RuleForm.java | 24 ++++++++++- 6 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c5f3f6b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java index 12906db..847826d 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import ru.ulstu.fc.project.model.Project; import ru.ulstu.fc.project.model.ProjectForm; +import ru.ulstu.fc.project.service.ProjectService; import ru.ulstu.fc.rule.model.Rule; import ru.ulstu.fc.rule.model.RuleForm; @@ -16,7 +17,7 @@ import ru.ulstu.fc.rule.model.RuleForm; @RequestMapping("rule") public class RuleController { private final RuleService ruleService; - + public RuleController(RuleService ruleService) { this.ruleService = ruleService; } diff --git a/src/main/java/ru/ulstu/fc/rule/controller/RuleService.java b/src/main/java/ru/ulstu/fc/rule/controller/RuleService.java index a4df3c9..8e7d89a 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/RuleService.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/RuleService.java @@ -1,5 +1,43 @@ package ru.ulstu.fc.rule.controller; -public class RuleService { +import org.springframework.stereotype.Service; +import ru.ulstu.fc.project.repository.RuleRepository; +import ru.ulstu.fc.project.service.ProjectService; +import ru.ulstu.fc.rule.model.Rule; +import ru.ulstu.fc.rule.model.RuleForm; + +@Service +public class RuleService { + private final RuleRepository ruleRepository; + private final ProjectService projectService; + + public RuleService(RuleRepository ruleRepository, ProjectService projectService) { + this.ruleRepository = ruleRepository; + this.projectService = projectService; + } + + public Rule getById(Integer id) { + return ruleRepository + .findById(id) + .orElseThrow(() -> new RuntimeException("Rule not found by id")); + } + + public Object save(RuleForm ruleForm) { + if (ruleForm.getId() == null) { + Rule rule = new Rule(); + rule.setProject(projectService.getById(ruleForm.getProjectId())); + // rule.set... + return ruleRepository.save(rule); + } + Rule dbRule = getById(ruleForm.getId()); + dbRule.setProject(projectService.getById(ruleForm.getProjectId())); + // dbRule.set ... + return ruleRepository.save(dbRule); + } + + public void delete(RuleForm ruleForm) { + getById(ruleForm.getId()); + ruleRepository.deleteById(ruleForm.getId()); + } } diff --git a/src/main/java/ru/ulstu/fc/rule/model/Antecedent.java b/src/main/java/ru/ulstu/fc/rule/model/Antecedent.java index 6950aa1..7df29b5 100644 --- a/src/main/java/ru/ulstu/fc/rule/model/Antecedent.java +++ b/src/main/java/ru/ulstu/fc/rule/model/Antecedent.java @@ -13,17 +13,13 @@ public class Antecedent extends BaseEntity { public Variable getVariable() { return variable; } - public void setVariable(Variable variable) { this.variable = variable; } - public String getValue() { return value; } - public void setValue(String value) { this.value = value; } - } diff --git a/src/main/java/ru/ulstu/fc/rule/model/Rule.java b/src/main/java/ru/ulstu/fc/rule/model/Rule.java index 2d929c6..cb071cb 100644 --- a/src/main/java/ru/ulstu/fc/rule/model/Rule.java +++ b/src/main/java/ru/ulstu/fc/rule/model/Rule.java @@ -17,6 +17,9 @@ public class Rule extends BaseEntity { @ManyToOne private Consequent consequent; + public Rule() { + } + public Project getProject() { return project; } diff --git a/src/main/java/ru/ulstu/fc/rule/model/RuleForm.java b/src/main/java/ru/ulstu/fc/rule/model/RuleForm.java index 0f774a9..e9d8629 100644 --- a/src/main/java/ru/ulstu/fc/rule/model/RuleForm.java +++ b/src/main/java/ru/ulstu/fc/rule/model/RuleForm.java @@ -1,10 +1,32 @@ package ru.ulstu.fc.rule.model; public class RuleForm { - private final Integer projectId; + private Integer id; + private Integer projectId; + + public RuleForm() { + } + + public RuleForm(Rule rule) { + this.projectId = (rule == null || rule.getProject() == null) + ? null + : rule.getProject().getId(); + } public Integer getProjectId() { return projectId; } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public void setProjectId(Integer projectId) { + this.projectId = projectId; + } } From c2019def08c2d68ccd7ba073ae86d77019ee21d7 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 17 Feb 2025 15:00:45 +0400 Subject: [PATCH 14/18] #13 -- Add rule edit form --- .../fc/rule/controller/RuleController.java | 9 ++---- src/main/resources/application.properties | 2 ++ src/main/resources/templates/rule/edit.html | 28 +++++++++++++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/main/resources/templates/rule/edit.html diff --git a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java index 847826d..5788d53 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java @@ -7,9 +7,6 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import ru.ulstu.fc.project.model.Project; -import ru.ulstu.fc.project.model.ProjectForm; -import ru.ulstu.fc.project.service.ProjectService; import ru.ulstu.fc.rule.model.Rule; import ru.ulstu.fc.rule.model.RuleForm; @@ -17,7 +14,7 @@ import ru.ulstu.fc.rule.model.RuleForm; @RequestMapping("rule") public class RuleController { private final RuleService ruleService; - + public RuleController(RuleService ruleService) { this.ruleService = ruleService; } @@ -35,7 +32,7 @@ public class RuleController { @PostMapping(value = "save", params = "save") public String save(RuleForm ruleForm, Model model) { model.addAttribute("rule", ruleService.save(ruleForm)); - return "redirect:/project/edit/"+ruleForm.getProjectId(); + return "redirect:/project/edit/" + ruleForm.getProjectId(); } @PostMapping(value = "save", params = "delete") @@ -43,6 +40,6 @@ public class RuleController { if (ruleForm != null && ruleForm.getId() != null) { ruleService.delete(ruleForm); } - return "redirect:/project/edit/"+ruleForm.getProjectId(); + return "redirect:/project/edit/" + ruleForm.getProjectId(); } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 261c422..4f4bd5b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,6 +7,8 @@ logging.level.ru.ulstu=DEBUG logging.level.sun.rmi.transport=off logging.level.javax.management.remote.rmi=off logging.level.java.rmi.server=off +logging.level.org.apache.tomcat=INFO +logging.level.org.apache.tomcat.util.net=WARN extractor.custom-projects-dir= server.error.include-stacktrace=always server.error.include-exception=true diff --git a/src/main/resources/templates/rule/edit.html b/src/main/resources/templates/rule/edit.html new file mode 100644 index 0000000..c9551a2 --- /dev/null +++ b/src/main/resources/templates/rule/edit.html @@ -0,0 +1,28 @@ + + + + Редактирование правила + + +
+

Редактирование правила:

+
+ +
+ + +
+ + + + Отмена +
+
+ From 73b5dd47df857cdf4d1579e99247c5346fe17fab Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 17 Feb 2025 15:12:33 +0400 Subject: [PATCH 15/18] #13 -- Add jenkinsfile --- Jenkinsfile | 35 +++++++++++++++++++++++++++++++++++ deploy/nio17.sh | 4 ++++ 2 files changed, 39 insertions(+) create mode 100644 Jenkinsfile create mode 100644 deploy/nio17.sh diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..7b55e10 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,35 @@ +pipeline { + agent any + stages { + stage('Test') { + steps { + script { + sh "sh ./gradlew clean test" + } + } + } + stage('Build') { + steps { + script { + sh "sh ./gradlew clean build" + } + } + } + stage('Deploy') { + steps { + script { + sh "sh deploy/nio17.sh" + } + } + } + } + post { + always { + script { + if (currentBuild.currentResult == 'FAILURE') { + step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "a.romanov@ulstu.ru", sendToIndividuals: true]) + } + } + } + } +} \ No newline at end of file diff --git a/deploy/nio17.sh b/deploy/nio17.sh new file mode 100644 index 0000000..d8845c9 --- /dev/null +++ b/deploy/nio17.sh @@ -0,0 +1,4 @@ +#!/bin/bash +bash ./gradlew assemble +scp -o StrictHostKeyChecking=no build/libs/fuzzy-controller-0.0.1-SNAPSHOT.jar root@192.168.1.129:/root/fuzzy-controller.jar +ssh root@192.168.1.129 "bash /root/run-fc.sh" \ No newline at end of file From 48e65bd53d4be5dd203a1053302071e7a7074d15 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 18 Feb 2025 11:30:06 +0400 Subject: [PATCH 16/18] #13 -- Fix ci --- Jenkinsfile | 12 ++++-------- deploy/nio17.sh | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7b55e10..f04f27e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,13 +1,9 @@ pipeline { agent any + tools { + jdk 'jdk-21' + } stages { - stage('Test') { - steps { - script { - sh "sh ./gradlew clean test" - } - } - } stage('Build') { steps { script { @@ -18,7 +14,7 @@ pipeline { stage('Deploy') { steps { script { - sh "sh deploy/nio17.sh" + sh "bash deploy/nio17.sh &" } } } diff --git a/deploy/nio17.sh b/deploy/nio17.sh index d8845c9..8334d4a 100644 --- a/deploy/nio17.sh +++ b/deploy/nio17.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/ bash ./gradlew assemble scp -o StrictHostKeyChecking=no build/libs/fuzzy-controller-0.0.1-SNAPSHOT.jar root@192.168.1.129:/root/fuzzy-controller.jar -ssh root@192.168.1.129 "bash /root/run-fc.sh" \ No newline at end of file +ssh root@192.168.1.129 "killall java >> /dev/null && /opt/jdk-21/bin/java -jar /root/fuzzy-controller.jar >> /root/fc.log &" \ No newline at end of file From 63ec2cc289ba02e9d96dee0a7a222f1cc461b0b6 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 18 Feb 2025 12:03:15 +0400 Subject: [PATCH 17/18] #13 -- Add link to rule edit page --- .../java/ru/ulstu/fc/rule/controller/RuleController.java | 7 +++++-- .../ulstu/fc/rule/{controller => service}/RuleService.java | 2 +- src/main/resources/templates/project/edit.html | 1 + src/main/resources/templates/rule/edit.html | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) rename src/main/java/ru/ulstu/fc/rule/{controller => service}/RuleService.java (97%) diff --git a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java index 5788d53..6107baa 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java +++ b/src/main/java/ru/ulstu/fc/rule/controller/RuleController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import ru.ulstu.fc.rule.model.Rule; import ru.ulstu.fc.rule.model.RuleForm; +import ru.ulstu.fc.rule.service.RuleService; @Controller @RequestMapping("rule") @@ -19,8 +20,10 @@ public class RuleController { this.ruleService = ruleService; } - @GetMapping("/edit/{ruleId}") - public String edit(@PathVariable(value = "ruleId") Integer id, Model model) { + @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("rule", new RuleForm((id != null && id != 0) ? ruleService.getById(id) diff --git a/src/main/java/ru/ulstu/fc/rule/controller/RuleService.java b/src/main/java/ru/ulstu/fc/rule/service/RuleService.java similarity index 97% rename from src/main/java/ru/ulstu/fc/rule/controller/RuleService.java rename to src/main/java/ru/ulstu/fc/rule/service/RuleService.java index 8e7d89a..929892a 100644 --- a/src/main/java/ru/ulstu/fc/rule/controller/RuleService.java +++ b/src/main/java/ru/ulstu/fc/rule/service/RuleService.java @@ -1,4 +1,4 @@ -package ru.ulstu.fc.rule.controller; +package ru.ulstu.fc.rule.service; import org.springframework.stereotype.Service; diff --git a/src/main/resources/templates/project/edit.html b/src/main/resources/templates/project/edit.html index aa796e0..ed29db0 100644 --- a/src/main/resources/templates/project/edit.html +++ b/src/main/resources/templates/project/edit.html @@ -68,5 +68,6 @@ И / ИЛИ
+ Добавить правило
diff --git a/src/main/resources/templates/rule/edit.html b/src/main/resources/templates/rule/edit.html index c9551a2..81b03d1 100644 --- a/src/main/resources/templates/rule/edit.html +++ b/src/main/resources/templates/rule/edit.html @@ -9,6 +9,7 @@

Редактирование правила:

+
@@ -22,7 +23,7 @@ onclick="return confirm('Удалить запись?')"> Удалить - Отмена + Отмена
From ecf5e1fab9b6ac2274662da8a4b5557c75fc85a5 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 18 Feb 2025 14:02:43 +0400 Subject: [PATCH 18/18] #13 -- Add buttons --- .../fc/config/SecurityConfiguration.java | 1 + .../fc/config/TemplateConfiguration.java | 4 +- src/main/resources/templates/default.html | 100 ++++++++++-------- src/main/resources/templates/login.html | 3 +- src/main/resources/templates/register.html | 28 ++--- 5 files changed, 78 insertions(+), 58 deletions(-) diff --git a/src/main/java/ru/ulstu/fc/config/SecurityConfiguration.java b/src/main/java/ru/ulstu/fc/config/SecurityConfiguration.java index 7547aaa..18900be 100644 --- a/src/main/java/ru/ulstu/fc/config/SecurityConfiguration.java +++ b/src/main/java/ru/ulstu/fc/config/SecurityConfiguration.java @@ -19,6 +19,7 @@ public class SecurityConfiguration { private final String[] permittedUrls = new String[]{ "/login", "/index", "/user/register", "/public/**", "/organizers", "/webjars/**", + "/error", "/register", "/h2-console/*", "/h2-console", "/css/**", "/js/**", "/img/**", "/templates/**", "/webjars/**"}; diff --git a/src/main/java/ru/ulstu/fc/config/TemplateConfiguration.java b/src/main/java/ru/ulstu/fc/config/TemplateConfiguration.java index 118618c..8ecec34 100644 --- a/src/main/java/ru/ulstu/fc/config/TemplateConfiguration.java +++ b/src/main/java/ru/ulstu/fc/config/TemplateConfiguration.java @@ -3,6 +3,7 @@ package ru.ulstu.fc.config; import nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.thymeleaf.extras.springsecurity6.dialect.SpringSecurityDialect; import org.thymeleaf.spring6.SpringTemplateEngine; import org.thymeleaf.templateresolver.ITemplateResolver; @@ -10,10 +11,11 @@ import org.thymeleaf.templateresolver.ITemplateResolver; public class TemplateConfiguration { @Bean - public SpringTemplateEngine templateEngine(ITemplateResolver templateResolver) { + public SpringTemplateEngine templateEngine(ITemplateResolver templateResolver, SpringSecurityDialect sec) { final SpringTemplateEngine templateEngine = new SpringTemplateEngine(); templateEngine.addTemplateResolver(templateResolver); templateEngine.addDialect(new LayoutDialect()); + templateEngine.addDialect(sec); return templateEngine; } } diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index e6a830d..783a0fc 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -1,57 +1,71 @@ - + + - + Нечеткий контроллер - + - - - + + + - - -
- -
- -
-
+ \ No newline at end of file diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html index d84a8aa..a903e3b 100644 --- a/src/main/resources/templates/login.html +++ b/src/main/resources/templates/login.html @@ -24,7 +24,8 @@
- + + Регистрация
diff --git a/src/main/resources/templates/register.html b/src/main/resources/templates/register.html index a56d912..be9a380 100644 --- a/src/main/resources/templates/register.html +++ b/src/main/resources/templates/register.html @@ -1,26 +1,28 @@
-

form

+

Регистрация

-
- - +
+ +

Validation error

-
- - +
+ +

Validation error

-
- - +
+ +
- + + Вернуться на страницу входа - - login