Search in sources :

Example 16 with Repo

use of com.searchcode.app.dao.Repo in project searchcode-server by boyter.

the class AdminRouteService method adminRepo.

public Map<String, Object> adminRepo(Request request, Response response) {
    Map<String, Object> map = new HashMap<>();
    Repo repo = Singleton.getRepo();
    int repoCount = repo.getRepoCount();
    String offSet = request.queryParams("offset");
    String searchQuery = request.queryParams("q");
    int indexOffset = 0;
    if (offSet != null) {
        try {
            indexOffset = Integer.parseInt(offSet);
            if (indexOffset > repoCount || indexOffset < 0) {
                indexOffset = 0;
            }
        } catch (NumberFormatException ex) {
            indexOffset = 0;
        }
    }
    if (searchQuery != null) {
        map.put("repoResults", repo.searchRepo(searchQuery));
    } else {
        map.put("repoResults", repo.getPagedRepo(indexOffset, 100));
    }
    map.put("searchQuery", searchQuery);
    map.put("hasPrevious", indexOffset > 0);
    map.put("hasNext", (indexOffset + 100) < repoCount);
    map.put("previousOffset", "" + (indexOffset - 100));
    map.put("nextOffset", "" + (indexOffset + 100));
    map.put("repoCount", this.getStat("repoCount"));
    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)

Example 17 with Repo

use of com.searchcode.app.dao.Repo in project searchcode-server by boyter.

the class ApiRouteServiceTest method testGetIndexTime.

public void testGetIndexTime() {
    Request mockRequest = mock(Request.class);
    Repo repoMock = mock(Repo.class);
    when(mockRequest.queryParams("reponame")).thenReturn("somename");
    when(mockRequest.queryParams()).thenReturn((new HashMap<String, String>() {

        {
            put("reponame", "reponame");
        }
    }).keySet());
    when(repoMock.getRepoByName("somename")).thenReturn(new RepoResult(0, "name", "scm", "url", "username", "password", "source", "branch", "\n" + "{\"rowId\":1,\"name\":\"test\",\"scm\":\"git\",\"url\":\"/test/\",\"username\":\"\",\"password\":\"\",\"source\":\"\",\"branch\":\"master\",\"data\":{\"averageIndexTimeSeconds\":9,\"indexStatus\":\"success\",\"jobRunTime\":{\"seconds\":1496356541,\"nanos\":188000000}}}"));
    ApiRouteService apiRouteService = new ApiRouteService(null, null, repoMock, null, null);
    String averageIndexTimeSeconds = apiRouteService.getIndexTime(mockRequest, null);
    assertThat(averageIndexTimeSeconds).isEqualTo("0 seconds ago");
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Request(spark.Request) RepoResult(com.searchcode.app.model.RepoResult)

Example 18 with Repo

use of com.searchcode.app.dao.Repo in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoAddNoAuthSucessful.

public void testRepoAddNoAuthSucessful() {
    Request mockRequest = Mockito.mock(Request.class);
    Repo mockRepo = Mockito.mock(Repo.class);
    ValidatorService mockValidatorService = Mockito.mock(ValidatorService.class);
    when(mockValidatorService.validate(any())).thenReturn(new ValidatorResult(true, ""));
    ApiRouteService apiRouteService = new ApiRouteService(null, null, mockRepo, null, mockValidatorService);
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = false;
    when(mockRequest.queryParams("reponame")).thenReturn("test");
    when(mockRequest.queryParams("repourl")).thenReturn("test");
    when(mockRequest.queryParams("repotype")).thenReturn("test");
    when(mockRequest.queryParams("repousername")).thenReturn("test");
    when(mockRequest.queryParams("repopassword")).thenReturn("test");
    when(mockRequest.queryParams("reposource")).thenReturn("test");
    when(mockRequest.queryParams("repobranch")).thenReturn("test");
    ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("added repository successfully");
    assertThat(apiResponse.isSucessful()).isTrue();
    verify(mockRepo, times(1)).saveRepo(Matchers.<RepoResult>anyObject());
}
Also used : Repo(com.searchcode.app.dao.Repo) ApiRouteService(com.searchcode.app.service.route.ApiRouteService) ValidatorResult(com.searchcode.app.model.ValidatorResult) Request(spark.Request) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 19 with Repo

use of com.searchcode.app.dao.Repo in project searchcode-server by boyter.

the class ValidatorServiceTest method testValidatorServiceExistingName.

public void testValidatorServiceExistingName() {
    Repo mockRepo = mock(Repo.class);
    ValidatorService validatorService = new ValidatorService(mockRepo, new Helpers());
    when(mockRepo.getRepoByName("exists")).thenReturn(new RepoResult());
    RepoResult repoResult = new RepoResult(0, "exists", "something", "url", "", "", "source", "branch", "{}");
    ValidatorResult validate = validatorService.validate(repoResult);
    assertThat(validate.isValid).isFalse();
}
Also used : Repo(com.searchcode.app.dao.Repo) Helpers(com.searchcode.app.util.Helpers) ValidatorResult(com.searchcode.app.model.ValidatorResult) RepoResult(com.searchcode.app.model.RepoResult)

Example 20 with Repo

use of com.searchcode.app.dao.Repo in project searchcode-server by boyter.

the class App method preStart.

/**
     * Called on startup to run all the DAO object table creation/migration logic. Slight overhead using this technique.
     * TODO Do the migrations inside the sqlite database so the application does not need to
     */
public static void preStart() {
    // Database migrations
    Data data = Singleton.getData();
    Repo repo = Singleton.getRepo();
    Api api = Singleton.getApi();
    data.createTableIfMissing();
    api.createTableIfMissing();
    repo.createTableIfMissing();
    repo.addSourceToTable();
    repo.addBranchToTable();
    repo.addDataToTable();
}
Also used : Repo(com.searchcode.app.dao.Repo) Data(com.searchcode.app.dao.Data) Api(com.searchcode.app.dao.Api)

Aggregations

Repo (com.searchcode.app.dao.Repo)36 Request (spark.Request)28 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)24 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)22 ApiResponse (com.searchcode.app.dto.api.ApiResponse)20 RepoResult (com.searchcode.app.model.RepoResult)14 ValidatorResult (com.searchcode.app.model.ValidatorResult)5 Data (com.searchcode.app.dao.Data)4 CodeSearcher (com.searchcode.app.service.CodeSearcher)3 AdminRouteService (com.searchcode.app.service.route.AdminRouteService)3 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)3 Gson (com.google.gson.Gson)2 CodeMatcher (com.searchcode.app.service.CodeMatcher)2 Helpers (com.searchcode.app.util.Helpers)2 ModelAndView (spark.ModelAndView)2 App (com.searchcode.app.App)1 SQLiteMemoryDatabaseConfig (com.searchcode.app.config.SQLiteMemoryDatabaseConfig)1 Values (com.searchcode.app.config.Values)1 Api (com.searchcode.app.dao.Api)1 com.searchcode.app.dto (com.searchcode.app.dto)1