fix indexing UI

This commit is contained in:
Anton Romanov 2021-04-05 11:05:45 +04:00
parent dc99cd6ab2
commit 8365cf825a
3 changed files with 24 additions and 6 deletions

View File

@ -25,6 +25,9 @@ import ru.ulstu.extractor.model.LineChange;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
@ -141,10 +144,22 @@ public class GitRepositoryService {
} }
private File getProjectDirectoryFile(String url) { private File getProjectDirectoryFile(String url) {
validateUrl(url);
return Path.of(getProjectDirectory(url)) return Path.of(getProjectDirectory(url))
.toFile(); .toFile();
} }
private void validateUrl(String url) {
if (url == null || url.isEmpty()) {
throw new RuntimeException("Repository url must not empty");
}
try {
new URL(url).toURI();
} catch (MalformedURLException | URISyntaxException e) {
throw new RuntimeException("Repository url not valid");
}
}
private boolean projectDirExists(File file) { private boolean projectDirExists(File file) {
return file.exists(); return file.exists();
} }

View File

@ -48,15 +48,16 @@ public class IndexService {
public void index(@NotNull String repositoryUrl, @NotNull String branchName) throws GitAPIException, IOException { public void index(@NotNull String repositoryUrl, @NotNull String branchName) throws GitAPIException, IOException {
Repository repository = repositoryRepository.findByUrl(repositoryUrl); Repository repository = repositoryRepository.findByUrl(repositoryUrl);
if (repository == null) { if (repository == null) {
repositoryRepository.save(new Repository(repositoryUrl)); repository = repositoryRepository.save(new Repository(repositoryUrl));
} }
Branch branch = branchRepository.findByRepositoryAndName(repository, branchName); Branch branch = branchRepository.findByRepositoryAndName(repository, branchName);
if (branch == null) { if (branch == null) {
branch = branchRepository.save(new Branch(repository, branchName)); branch = branchRepository.save(new Branch(repository, branchName));
} }
List<Commit> commits = gitRepositoryService.getCommits(repositoryUrl, branchName); List<Commit> commits = gitRepositoryService.getCommits(repositoryUrl, branchName);
commitRepository.deleteAll(branch.getCommits()); List<Commit> commitsToRemove = branch.getCommits();
branch.getCommits().clear(); branch.getCommits().clear();
commitRepository.deleteAll(commitsToRemove);
branch.setCommits(commits); branch.setCommits(commits);
branchRepository.save(branch); branchRepository.save(branch);
} }

View File

@ -11,11 +11,12 @@
<form action="#" th:action="${@route.INDEXING_NEW_REPOSITORY}" th:object="${repoForm}" method="post"> <form action="#" th:action="${@route.INDEXING_NEW_REPOSITORY}" th:object="${repoForm}" method="post">
<button class="btn btn-outline-dark dropdown-toggle" type="button" data-toggle="collapse" <button class="btn btn-outline-dark dropdown-toggle" type="button" data-toggle="collapse"
data-target="#collapseOne" aria-expanded="false" aria-controls="collapseExample" data-target="#collapseOne" aria-expanded="false" aria-controls="collapseExample"
th:if="${repoForm.repo != null}" th:if="${repoForm.repo != '' && repoForm.repo != null && (error == '' || error == null)}"
th:text="${repoForm.repo == null ? 'Репозиторий' : repoForm.repo}"> th:text="${repoForm.repo == '' || repoForm.repo == null ? 'Репозиторий' : repoForm.repo}">
Button with data-target Button with data-target
</button> </button>
<div id="collapseOne" th:class="${repoForm.repo == null ? 'collapse show' : 'collapse'}" <div id="collapseOne"
th:class="${repoForm.repo == '' || repoForm.repo == null || (error != '' && error != null) ? 'collapse show' : 'collapse'}"
aria-labelledby="headingOne"> aria-labelledby="headingOne">
<div class="card-body"> <div class="card-body">
<div class="form-group"> <div class="form-group">
@ -34,7 +35,8 @@
</div> </div>
</div> </div>
</div> </div>
<div id="collapseTwo" class="collapse show" aria-labelledby="headingOne" th:if="${repoForm.repo != null}"> <div id="collapseTwo" class="collapse show" aria-labelledby="headingOne"
th:if="${repoForm.repo != '' && repoForm.repo != null && (error == '' || error == null) }">
<div class="card-body"> <div class="card-body">
<div class="form-group"> <div class="form-group">
<label for="select-branch">Ветки:</label> <label for="select-branch">Ветки:</label>