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;
}
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);
}
Aggregations