diff --git a/src/main/java/ru/ulstu/extractor/author/repository/AuthorRepository.java b/src/main/java/ru/ulstu/extractor/author/repository/AuthorRepository.java index e20f19d..2ad2ceb 100644 --- a/src/main/java/ru/ulstu/extractor/author/repository/AuthorRepository.java +++ b/src/main/java/ru/ulstu/extractor/author/repository/AuthorRepository.java @@ -20,5 +20,5 @@ public interface AuthorRepository extends JpaRepository { List findByName(String name); @Query("SELECT DISTINCT a.name FROM Commit c, Branch b, Author a WHERE c.author = a AND c.branch = b AND (:branchId IS NULL OR b.id = :branchId) AND a.name IS NOT NULL AND a.name <> '' ORDER BY a.name") - List findByBranchId(Integer branchId); + List findByBranchId(@Param("branchId") Integer branchId); } diff --git a/src/main/java/ru/ulstu/extractor/recommendation/controller/RecommendationController.java b/src/main/java/ru/ulstu/extractor/recommendation/controller/RecommendationController.java new file mode 100644 index 0000000..a303067 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/recommendation/controller/RecommendationController.java @@ -0,0 +1,39 @@ +package ru.ulstu.extractor.recommendation.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import ru.ulstu.extractor.branch.service.BranchService; +import ru.ulstu.extractor.recommendation.model.FilterBranchForm; +import ru.ulstu.extractor.rule.service.FuzzyInferenceService; +import springfox.documentation.annotations.ApiIgnore; + +import java.util.Optional; + +import static ru.ulstu.extractor.core.Route.RECOMMENDATIONS; + +@Controller +@ApiIgnore +public class RecommendationController { + private final FuzzyInferenceService fuzzyInferenceService; + private final BranchService branchService; + + public RecommendationController(FuzzyInferenceService fuzzyInferenceService, + BranchService branchService) { + this.fuzzyInferenceService = fuzzyInferenceService; + this.branchService = branchService; + } + + @GetMapping(RECOMMENDATIONS) + public String getRecommendations(Model model, @RequestParam Optional branchId) { + model.addAttribute("branches", branchService.findAll()); + if (branchId.isPresent()) { + model.addAttribute("recommendations", fuzzyInferenceService.getRecommendations()); + model.addAttribute("filterBranchForm", new FilterBranchForm(branchId.get())); + } else { + model.addAttribute("filterBranchForm", new FilterBranchForm()); + } + return RECOMMENDATIONS; + } +} diff --git a/src/main/java/ru/ulstu/extractor/recommendation/model/FilterBranchForm.java b/src/main/java/ru/ulstu/extractor/recommendation/model/FilterBranchForm.java new file mode 100644 index 0000000..0d331c3 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/recommendation/model/FilterBranchForm.java @@ -0,0 +1,20 @@ +package ru.ulstu.extractor.recommendation.model; + +public class FilterBranchForm { + private Integer branchId; + + public FilterBranchForm() { + } + + public FilterBranchForm(Integer branchId) { + this.branchId = branchId; + } + + public Integer getBranchId() { + return branchId; + } + + public void setBranchId(Integer branchId) { + this.branchId = branchId; + } +} diff --git a/src/main/java/ru/ulstu/extractor/rule/controller/RecommendationController.java b/src/main/java/ru/ulstu/extractor/rule/controller/RecommendationController.java deleted file mode 100644 index 1db00c0..0000000 --- a/src/main/java/ru/ulstu/extractor/rule/controller/RecommendationController.java +++ /dev/null @@ -1,25 +0,0 @@ -package ru.ulstu.extractor.rule.controller; - -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import ru.ulstu.extractor.rule.service.FuzzyInferenceService; -import springfox.documentation.annotations.ApiIgnore; - -import static ru.ulstu.extractor.core.Route.RECOMMENDATIONS; - -@Controller -@ApiIgnore -public class RecommendationController { - private final FuzzyInferenceService fuzzyInferenceService; - - public RecommendationController(FuzzyInferenceService fuzzyInferenceService) { - this.fuzzyInferenceService = fuzzyInferenceService; - } - - @GetMapping(RECOMMENDATIONS) - public String getRecommendations(Model model) { - model.addAttribute("recommendations", fuzzyInferenceService.run()); - return RECOMMENDATIONS; - } -} diff --git a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java index 88e0026..6ec146e 100644 --- a/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java +++ b/src/main/java/ru/ulstu/extractor/rule/service/FuzzyInferenceService.java @@ -96,10 +96,11 @@ public class FuzzyInferenceService { return engine; } - public String run() { + public String getRecommendations() { Engine engine = getFuzzyEngine(); List antecedentValues = antecedentValueService.getList(); Map variableValues = new HashMap<>(); + variableValues.put("COMMITS", 0.0); variableValues.put("AUTHORS", 0.0); engine.addRuleBlock(getRuleBlock(engine, variableValues, antecedentValues)); diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index 1b59df9..d118ca8 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -38,10 +38,10 @@ Link diff --git a/src/main/resources/templates/recommendations.html b/src/main/resources/templates/recommendations.html index dbcebe5..7d43881 100644 --- a/src/main/resources/templates/recommendations.html +++ b/src/main/resources/templates/recommendations.html @@ -1,12 +1,42 @@ Простая обработка формы на Spring MVC
-
+
+
+
+ Репозиторий-ветка +
+
+ + +
+ +
+
Выбрерите ветку для получения рекомендаций
+ + +
+
+
+