#76 -- fix part

pull/75/head
Anton Romanov 2 years ago
parent c39bc3c6ca
commit 8cb6fdf082

@ -20,5 +20,5 @@ public interface AuthorRepository extends JpaRepository<Author, Integer> {
List<Author> 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<String> findByBranchId(Integer branchId);
List<String> findByBranchId(@Param("branchId") Integer branchId);
}

@ -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<Integer> 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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -96,10 +96,11 @@ public class FuzzyInferenceService {
return engine;
}
public String run() {
public String getRecommendations() {
Engine engine = getFuzzyEngine();
List<AntecedentValue> antecedentValues = antecedentValueService.getList();
Map<String, Double> variableValues = new HashMap<>();
variableValues.put("COMMITS", 0.0);
variableValues.put("AUTHORS", 0.0);
engine.addRuleBlock(getRuleBlock(engine, variableValues, antecedentValues));

@ -38,10 +38,10 @@
<a class="nav-link" href="/statistic" th:text="#{messages.menu.statistic}">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/recommendations" th:text="Рекомендации">Link</a>
<a class="nav-link" href="/listRules" th:text="Правила">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/listRules" th:text="Правила">Link</a>
<a class="nav-link" href="/recommendations" th:text="Рекомендации">Link</a>
</li>
</ul>
</div>

@ -1,12 +1,42 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
layout:decorate="~{default}">
<head>
<title>Простая обработка формы на Spring MVC</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<div th:text="${recommendations}"></div>
<form action="#" th:action="${@route.RECOMMENDATIONS}" th:object="${filterBranchForm}" method="get">
<div class="row">
<div class="col-md-2 col-sm-12">
Репозиторий-ветка
</div>
<div class="col-md-6 col-sm-12">
<select id="select-branch" class="selectpicker" data-live-search="true" th:field="*{branchId}"
data-width="90%">
<option value="">Все ветки</option>
<option th:each="branch : ${branches}"
th:value="${branch.id}"
th:utext="${branch.gitRepository.url} + ' - '+ ${branch.name}">
</option>
</select>
<script th:inline="javascript">
$('#select-branch').val([[ * {branchId}]
])
;
$('#select-branch').selectpicker('refresh');
</script>
</div>
<input type="submit" class="btn btn-outline-success w-100" value="Применить фильтр"/>
</div>
<div th:if="*{branchId == null}">Выбрерите ветку для получения рекомендаций</div>
<input type="hidden" th:field="*{branchId}">
</form>
<div th:each="recommendation: ${recommendations}">
<div th:text="${recommendation}"></div>
</div>
</div>
</html>

Loading…
Cancel
Save