Search in sources :

Example 1 with SearchRepositoriesResult

use of org.haiku.haikudepotserver.api1.model.repository.SearchRepositoriesResult in project haikudepotserver by haiku.

the class RepositoryApiImpl method searchRepositories.

@Override
public SearchRepositoriesResult searchRepositories(SearchRepositoriesRequest request) {
    Preconditions.checkNotNull(request);
    final ObjectContext context = serverRuntime.newContext();
    if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.REPOSITORY_LIST)) {
        throw new AccessDeniedException("unable to view lists of repositories");
    }
    if (null != request.includeInactive && request.includeInactive) {
        if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.REPOSITORY_LIST_INACTIVE)) {
            throw new AccessDeniedException("unable to view lists of inactive repositories");
        }
    }
    RepositorySearchSpecification specification = new RepositorySearchSpecification();
    String exp = request.expression;
    if (null != exp) {
        exp = Strings.emptyToNull(exp.trim().toLowerCase());
    }
    specification.setExpression(exp);
    if (null != request.expressionType) {
        specification.setExpressionType(PkgSearchSpecification.ExpressionType.valueOf(request.expressionType.name()));
    }
    specification.setLimit(request.limit);
    specification.setOffset(request.offset);
    specification.setIncludeInactive(null != request.includeInactive && request.includeInactive);
    SearchRepositoriesResult result = new SearchRepositoriesResult();
    result.total = repositoryService.total(context, specification);
    result.items = Collections.emptyList();
    if (result.total > 0) {
        List<Repository> searchedRepositories = repositoryService.search(context, specification);
        result.items = searchedRepositories.stream().map(sr -> {
            SearchRepositoriesResult.Repository resultRepository = new SearchRepositoriesResult.Repository();
            resultRepository.active = sr.getActive();
            resultRepository.name = sr.getName();
            resultRepository.code = sr.getCode();
            return resultRepository;
        }).collect(Collectors.toList());
    }
    return result;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) RepositorySearchSpecification(org.haiku.haikudepotserver.repository.model.RepositorySearchSpecification) Repository(org.haiku.haikudepotserver.dataobjects.Repository) ObjectContext(org.apache.cayenne.ObjectContext) SearchRepositoriesResult(org.haiku.haikudepotserver.api1.model.repository.SearchRepositoriesResult)

Example 2 with SearchRepositoriesResult

use of org.haiku.haikudepotserver.api1.model.repository.SearchRepositoriesResult in project haikudepotserver by haiku.

the class RepositoryApiIT method searchRepositoriesTest.

@Test
public void searchRepositoriesTest() {
    integrationTestSupportService.createStandardTestData();
    SearchRepositoriesRequest request = new SearchRepositoriesRequest();
    request.expression = "test";
    request.expressionType = SearchPkgsRequest.ExpressionType.CONTAINS;
    request.limit = 2;
    request.offset = 0;
    // ------------------------------------
    SearchRepositoriesResult result = repositoryApi.searchRepositories(request);
    // ------------------------------------
    assertFoundRepository(result);
}
Also used : SearchRepositoriesRequest(org.haiku.haikudepotserver.api1.model.repository.SearchRepositoriesRequest) SearchRepositoriesResult(org.haiku.haikudepotserver.api1.model.repository.SearchRepositoriesResult) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

SearchRepositoriesResult (org.haiku.haikudepotserver.api1.model.repository.SearchRepositoriesResult)2 ObjectContext (org.apache.cayenne.ObjectContext)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 SearchRepositoriesRequest (org.haiku.haikudepotserver.api1.model.repository.SearchRepositoriesRequest)1 Repository (org.haiku.haikudepotserver.dataobjects.Repository)1 RepositorySearchSpecification (org.haiku.haikudepotserver.repository.model.RepositorySearchSpecification)1 Test (org.junit.jupiter.api.Test)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1