Search in sources :

Example 16 with ValidatorResult

use of com.searchcode.app.model.ValidatorResult in project searchcode-server by boyter.

the class AdminRouteService method postBulk.

public List<ValidatorResult> postBulk(Request request, Response response) {
    var repos = request.queryParams("repos");
    var repolines = repos.split("\\r?\\n");
    var validatorResults = new ArrayList<ValidatorResult>();
    for (String line : repolines) {
        var repoparams = line.split(",", -1);
        if (repoparams.length == 7) {
            var branch = repoparams[6].trim();
            if (branch.equals(Values.EMPTYSTRING)) {
                branch = "master";
            }
            var scm = repoparams[1].trim().toLowerCase();
            if (scm.equals(Values.EMPTYSTRING)) {
                scm = "git";
            }
            RepoResult repoResult = new RepoResult().setRowId(-1).setName(repoparams[0]).setScm(scm).setUrl(repoparams[2]).setUsername(repoparams[3]).setPassword(repoparams[4]).setSource(repoparams[5]).setBranch(branch).setData("{}");
            var validate = this.validatorService.validate(repoResult, false);
            if (validate.isValid) {
                this.repo.saveRepo(repoResult);
                this.jobService.forceEnqueue(repoResult);
            } else {
                validate.setLine(line);
                validatorResults.add(validate);
            }
        } else {
            ValidatorResult validate = new ValidatorResult(false, "Incorrect number of elements: " + line);
            validate.setLine(line);
            validatorResults.add(validate);
        }
    }
    return validatorResults;
}
Also used : ValidatorResult(com.searchcode.app.model.ValidatorResult) RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

ValidatorResult (com.searchcode.app.model.ValidatorResult)16 RepoResult (com.searchcode.app.model.RepoResult)12 SQLiteRepo (com.searchcode.app.dao.SQLiteRepo)5 Helpers (com.searchcode.app.util.Helpers)4 ApiResponse (com.searchcode.app.dto.api.ApiResponse)3 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)3 Request (spark.Request)3 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)2 LoggerWrapper (com.searchcode.app.util.LoggerWrapper)2 AdminRouteService (com.searchcode.app.service.route.AdminRouteService)1 JsonTransformer (com.searchcode.app.util.JsonTransformer)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 ModelAndView (spark.ModelAndView)1 FreeMarkerEngine (spark.template.freemarker.FreeMarkerEngine)1