#2 - add new filter

merge-requests/3/head
Anton Romanov 3 years ago
parent 3de5950389
commit 97b3762c78

@ -1,15 +1,17 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.controller;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ru.ulstu.extractor.model.Commit;
import ru.ulstu.extractor.service.GitRepositoryService;
import java.io.IOException;
import java.util.List;
import static ru.ulstu.extractor.RepoController.URL;
import static ru.ulstu.extractor.controller.RepoController.URL;
@RestController
@RequestMapping(URL)

@ -3,7 +3,7 @@ package ru.ulstu.extractor.db;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import ru.ulstu.extractor.Commit;
import ru.ulstu.extractor.model.Commit;
import java.sql.ResultSet;
import java.sql.SQLException;

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.model;
import java.util.ArrayList;
import java.util.List;

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.model;
import java.util.Date;

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.model;
import java.util.ArrayList;
import java.util.List;

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.model;
public class LineChange {
private boolean added;

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.model;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.diff.DiffFormatter;

@ -7,9 +7,19 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import ru.ulstu.extractor.mvc.model.FilterForm;
import ru.ulstu.extractor.mvc.model.RepoForm;
import ru.ulstu.extractor.service.FilteringService;
import ru.ulstu.extractor.service.GitRepositoryService;
@Controller
public class GitExtractorController {
private final FilteringService filteringService;
private final GitRepositoryService gitRepositoryService;
public GitExtractorController(FilteringService filteringService,
GitRepositoryService gitRepositoryService) {
this.filteringService = filteringService;
this.gitRepositoryService = gitRepositoryService;
}
@GetMapping("/newRepo")
public String indexNewRepo(Model model) {
@ -25,11 +35,17 @@ public class GitExtractorController {
@PostMapping("/sendRepo")
public String sendRepo(@ModelAttribute RepoForm repoForm, Model model) {
model.addAttribute("filterForm", new FilterForm());
if (repoForm.getRepo() == null || repoForm.getRepo().isEmpty()) {
model.addAttribute("error", "'Git' не должно быть пустым");
return "newRepo";
}
model.addAttribute("filterForm", new FilterForm(repoForm.getRepo()));
try {
gitRepositoryService.cloneOrUpdateRepo(repoForm.getRepo());
} catch (Exception ex) {
model.addAttribute("error", ex.getMessage());
return "newRepo";
}
return "filtering";
}
@ -39,6 +55,7 @@ public class GitExtractorController {
model.addAttribute("error", "'Строка' не должно быть пустым");
return "filtering";
}
model.addAttribute("commits", filteringService.getCommits(filterForm.getFilter(), filterForm.getFilter()));
return "resultRepo";
}
}

@ -10,7 +10,7 @@ public class MvcConfiguration implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/{articlename:\\w+}");
registry.addRedirectViewController("/", "/index");
registry.addRedirectViewController("/", "/newRepo");
registry.addRedirectViewController("/default", "/home");
}

@ -2,6 +2,14 @@ package ru.ulstu.extractor.mvc.model;
public class FilterForm {
private String filter;
private String url;
public FilterForm() {
}
public FilterForm(String url) {
this.url = url;
}
public String getFilter() {
return filter;
@ -11,6 +19,14 @@ public class FilterForm {
this.filter = filter;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@Override
public String toString() {
return "FilterForm{" +

@ -0,0 +1,32 @@
package ru.ulstu.extractor.service;
import org.springframework.stereotype.Service;
import ru.ulstu.extractor.model.Commit;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class FilteringService {
private final GitRepositoryService gitRepositoryService;
public FilteringService(GitRepositoryService gitRepositoryService) {
this.gitRepositoryService = gitRepositoryService;
}
public List<Commit> getCommits(String urlRepo) {
return getCommits(urlRepo, null);
}
public List<Commit> getCommits(String urlRepo, String filterCommitMessage) {
if (filterCommitMessage != null) {
return getCommits(urlRepo)
.stream()
.filter(commit -> commit.getMessage().contains(filterCommitMessage))
.collect(Collectors.toList());
} else {
return getCommits(urlRepo);
}
}
}

@ -1,4 +1,4 @@
package ru.ulstu.extractor;
package ru.ulstu.extractor.service;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
@ -8,6 +8,10 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import ru.ulstu.extractor.model.Changes;
import ru.ulstu.extractor.model.Commit;
import ru.ulstu.extractor.model.FileChange;
import ru.ulstu.extractor.model.LineChange;
import java.io.ByteArrayOutputStream;
import java.io.File;

@ -27,8 +27,22 @@
</select>
<p>Строки:<br>
<input type="text" size="40" th:field="*{filter}">
<input type="hidden" th:field="*{url}">
</p>
<p style="color:red" th:text="${error}"></p>
<table>
<tr>
<th>Author</th>
<th>Date</th>
<th>Commit</th>
</tr>
<tr th:each="commit : ${commits}">
<td th:text="${commit.author}">Onions</td>
<td th:text="${commit.date}">2.41</td>
<td th:text="${commit.message}">yes</td>
</tr>
</table>
<p>
<input type="submit" value="Отправить"/>
</p>

@ -0,0 +1,32 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
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">
<h1>Форма</h1>
<form action="#" th:action="@{/sendEmail}" th:object="${emailForm}" method="post">
<p style="color:red" th:text="${error}"></p>
<table>
<tr>
<td>Тема:</td>
<td><input type="text" th:field="*{subject}"/></td>
</tr>
<tr>
<td>Кому:</td>
<td><input type="text" th:field="*{to}"/></td>
</tr>
<tr>
<td>Сообщение:</td>
<td><textarea th:field="*{message}"/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Отправить"/></td>
</tr>
</table>
</form>
</div>
</html>
Loading…
Cancel
Save