use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class CodeRouteService method getRepositoryList.
public Map<String, Object> getRepositoryList(Request request, Response response) {
Map<String, Object> map = new HashMap<>();
Repo repo = Singleton.getRepo();
String offSet = request.queryParams("offset");
int pageSize = 20;
int indexOffset = Singleton.getHelpers().tryParseInt(offSet, "0");
List<RepoResult> pagedRepo = repo.getPagedRepo(pageSize * indexOffset, pageSize + 1);
boolean hasNext = pagedRepo.size() == (pageSize + 1);
boolean hasPrevious = indexOffset != 0;
if (hasNext) {
pagedRepo = pagedRepo.subList(0, pageSize);
}
map.put("hasPrevious", hasPrevious);
map.put("hasNext", hasNext);
map.put("repoList", pagedRepo);
map.put("nextOffset", indexOffset + 1);
map.put("previousOffset", indexOffset - 1);
map.put("logoImage", CommonRouteService.getLogo());
map.put("isCommunity", App.ISCOMMUNITY);
map.put(Values.EMBED, Singleton.getData().getDataByName(Values.EMBED, Values.EMPTYSTRING));
return map;
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class CodeRouteService method getProject.
public Map<String, Object> getProject(Request request, Response response) {
Map<String, Object> map = new HashMap<>();
String repoName = request.params(":reponame");
RepoResult repository = Singleton.getRepo().getRepoByName(repoName);
SearchcodeLib searchcodeLib = Singleton.getSearchCodeLib();
Cocomo2 coco = new Cocomo2();
Gson gson = new Gson();
if (repository == null) {
response.redirect("/404/");
halt();
}
ProjectStats projectStats = this.codeSearcher.getProjectStats(repository.getName());
map.put("busBlurb", searchcodeLib.generateBusBlurb(projectStats));
map.put("repoLocation", repository.getUrl());
map.put("repoBranch", repository.getBranch());
map.put("totalFiles", projectStats.getTotalFiles());
map.put("totalCodeLines", projectStats.getTotalCodeLines());
map.put("languageFacet", projectStats.getCodeFacetLanguages());
map.put("ownerFacet", projectStats.getRepoFacetOwner());
map.put("codeByLines", projectStats.getCodeByLines());
double estimatedEffort = coco.estimateEffort(projectStats.getTotalCodeLines());
map.put("estimatedEffort", estimatedEffort);
map.put("estimatedCost", (int) coco.estimateCost(estimatedEffort, CommonRouteService.getAverageSalary()));
map.put("totalOwners", projectStats.getRepoFacetOwner().size());
map.put("totalLanguages", projectStats.getCodeFacetLanguages().size());
map.put("ownerFacetJson", gson.toJson(projectStats.getRepoFacetOwner()));
map.put("languageFacetJson", gson.toJson(projectStats.getCodeFacetLanguages()));
map.put("repoName", repoName);
map.put("logoImage", CommonRouteService.getLogo());
map.put("isCommunity", App.ISCOMMUNITY);
map.put(Values.EMBED, Singleton.getData().getDataByName(Values.EMBED, Values.EMPTYSTRING));
return map;
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class ValidatorService method validate.
public ValidatorResult validate(RepoResult repoResult) {
if (repoResult == null || this.helpers.isNullEmptyOrWhitespace(repoResult.getName())) {
return new ValidatorResult(false, "Repository Name cannot be empty or whitespace");
}
if (this.helpers.isNullEmptyOrWhitespace(repoResult.getUrl())) {
return new ValidatorResult(false, "Repository Location cannot be empty or whitespace");
}
boolean matches = repoResult.getName().matches("^[a-zA-Z0-9-_]*$");
if (!matches) {
return new ValidatorResult(false, "Repository Name must match the regular expression ^[a-zA-Z0-9-_]*$");
}
RepoResult repoByName = this.repo.getRepoByName(repoResult.getName());
if (repoByName != null) {
return new ValidatorResult(false, "Repository Name must be unique");
}
return new ValidatorResult(true, Values.EMPTYSTRING);
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class AdminRouteService method deleteRepo.
public void deleteRepo(Request request, Response response) {
String repoName = request.queryParams("repoName");
RepoResult rr = this.repo.getRepoByName(repoName);
if (rr != null) {
this.dataService.addToPersistentDelete(rr.getName());
}
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class AdminRouteService method postRepo.
public ValidatorResult postRepo(Request request, Response response) {
String[] reponames = request.queryParamsValues("reponame");
String[] reposcms = request.queryParamsValues("reposcm");
String[] repourls = request.queryParamsValues("repourl");
String[] repousername = request.queryParamsValues("repousername");
String[] repopassword = request.queryParamsValues("repopassword");
String[] reposource = request.queryParamsValues("reposource");
String[] repobranch = request.queryParamsValues("repobranch");
ValidatorResult validate = new ValidatorResult(true, Values.EMPTYSTRING);
for (int i = 0; i < reponames.length; i++) {
String branch = repobranch[i].trim();
if (branch.equals(Values.EMPTYSTRING)) {
branch = "master";
}
RepoResult repoResult = new RepoResult(-1, reponames[i], reposcms[i], repourls[i], repousername[i], repopassword[i], reposource[i], branch, "{}");
validate = this.validatorService.validate(repoResult);
if (!validate.isValid) {
validate.setRepoResult(repoResult);
return validate;
}
this.repo.saveRepo(repoResult);
this.jobService.forceEnqueue(this.repo.getRepoByUrl(repourls[i]));
}
return validate;
}
Aggregations