Search in sources :

Example 41 with RepoResult

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;
}
Also used : Repo(com.searchcode.app.dao.Repo) RepoResult(com.searchcode.app.model.RepoResult)

Example 42 with RepoResult

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;
}
Also used : Gson(com.google.gson.Gson) RepoResult(com.searchcode.app.model.RepoResult)

Example 43 with RepoResult

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);
}
Also used : ValidatorResult(com.searchcode.app.model.ValidatorResult) RepoResult(com.searchcode.app.model.RepoResult)

Example 44 with RepoResult

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());
    }
}
Also used : RepoResult(com.searchcode.app.model.RepoResult)

Example 45 with RepoResult

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;
}
Also used : ValidatorResult(com.searchcode.app.model.ValidatorResult) RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

RepoResult (com.searchcode.app.model.RepoResult)59 Repo (com.searchcode.app.dao.Repo)13 ApiResponse (com.searchcode.app.dto.api.ApiResponse)9 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)9 Request (spark.Request)9 ValidatorResult (com.searchcode.app.model.ValidatorResult)8 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)8 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)8 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)5 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)3 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)2 RunningIndexJob (com.searchcode.app.dto.RunningIndexJob)2 File (java.io.File)2 Gson (com.google.gson.Gson)1 Data (com.searchcode.app.dao.Data)1 IndexBaseRepoJob (com.searchcode.app.jobs.repository.IndexBaseRepoJob)1 IndexFileRepoJob (com.searchcode.app.jobs.repository.IndexFileRepoJob)1