Search in sources :

Example 1 with Pageable

use of io.gravitee.rest.api.model.common.Pageable in project gravitee-management-rest-api by gravitee-io.

the class AbstractDocumentSearcher method search.

protected SearchResult search(Query query, Pageable pageable) throws TechnicalException {
    logger.debug("Searching for: {}", query.toString());
    try {
        IndexSearcher searcher = getIndexSearcher();
        TopDocs topDocs;
        if (pageable != null) {
            // TODO: How to find the accurate numhits ?
            TopScoreDocCollector collector = TopScoreDocCollector.create(1000);
            searcher.search(query, collector);
            topDocs = collector.topDocs((pageable.getPageNumber() - 1) * pageable.getPageSize(), pageable.getPageSize());
        } else {
            topDocs = searcher.search(query, Integer.MAX_VALUE);
        }
        final ScoreDoc[] hits = topDocs.scoreDocs;
        final List<String> results = new ArrayList<>();
        final List<Integer> orderdedDocsId = Arrays.stream(topDocs.scoreDocs).sorted((doc1, doc2) -> Float.compare(doc2.score, doc1.score)).map(doc -> doc.doc).collect(Collectors.toList());
        logger.debug("Found {} total matching documents", topDocs.totalHits);
        for (Integer docId : orderdedDocsId) {
            results.add(getReference(searcher.doc(docId)));
        }
        return new SearchResult(results.stream().distinct().collect(Collectors.toList()), topDocs.totalHits);
    } catch (IOException ioe) {
        logger.error("An error occurs while getting documents from search result", ioe);
        throw new TechnicalException("An error occurs while getting documents from search result", ioe);
    }
}
Also used : Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Pageable(io.gravitee.rest.api.model.common.Pageable) CustomWhitespaceAnalyzer(io.gravitee.rest.api.service.impl.search.lucene.analyzer.CustomWhitespaceAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) DirectoryReader(org.apache.lucene.index.DirectoryReader) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.apache.lucene.document.Document) IndexWriter(org.apache.lucene.index.IndexWriter) DocumentSearcher(io.gravitee.rest.api.service.impl.search.lucene.DocumentSearcher) org.apache.lucene.search(org.apache.lucene.search) SearchResult(io.gravitee.rest.api.service.impl.search.SearchResult) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ArrayList(java.util.ArrayList) SearchResult(io.gravitee.rest.api.service.impl.search.SearchResult) IOException(java.io.IOException)

Example 2 with Pageable

use of io.gravitee.rest.api.model.common.Pageable in project gravitee-management-rest-api by gravitee-io.

the class DefaultPageRevisionUpgrader method upgrade.

@Override
public boolean upgrade() {
    if (hasNoRevisions()) {
        logger.info("No page revisions found. Create a default revision based on pages.");
        final int pageSize = 100;
        int pageNumber = 0;
        Page<PageEntity> pagesSubSet = null;
        do {
            Pageable pageable = new PageableImpl(pageNumber, pageSize);
            pagesSubSet = pageService.findAll(pageable);
            if (!pagesSubSet.getContent().isEmpty()) {
                pagesSubSet.getContent().stream().filter(entity -> pageService.shouldHaveRevision(entity.getType())).forEach(entity -> pageRevisionService.create(convert(entity)));
                ++pageNumber;
            }
        } while (!pagesSubSet.getContent().isEmpty());
    }
    return true;
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) PageableImpl(io.gravitee.rest.api.model.common.PageableImpl) PageEntity(io.gravitee.rest.api.model.PageEntity) PageableImpl(io.gravitee.rest.api.model.common.PageableImpl) Upgrader(io.gravitee.rest.api.service.Upgrader) Ordered(org.springframework.core.Ordered) Logger(org.slf4j.Logger) Pageable(io.gravitee.rest.api.model.common.Pageable) Page(io.gravitee.common.data.domain.Page) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Component(org.springframework.stereotype.Component) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) PageService(io.gravitee.rest.api.service.PageService) PageRevisionService(io.gravitee.rest.api.service.PageRevisionService) Pageable(io.gravitee.rest.api.model.common.Pageable)

Example 3 with Pageable

use of io.gravitee.rest.api.model.common.Pageable in project gravitee-management-rest-api by gravitee-io.

the class UserServiceImpl method search.

@Override
public Page<UserEntity> search(UserCriteria criteria, Pageable pageable) {
    try {
        LOGGER.debug("search users");
        UserCriteria.Builder builder = new UserCriteria.Builder().organizationId(GraviteeContext.getCurrentOrganization()).statuses(criteria.getStatuses());
        if (criteria.hasNoStatus()) {
            builder.noStatus();
        }
        UserCriteria newCriteria = builder.build();
        Page<User> users = userRepository.search(newCriteria, new PageableBuilder().pageNumber(pageable.getPageNumber() - 1).pageSize(pageable.getPageSize()).build());
        List<UserEntity> entities = users.getContent().stream().map(u -> convert(u, false)).collect(toList());
        populateUserFlags(entities);
        return new Page<>(entities, users.getPageNumber() + 1, (int) users.getPageElements(), users.getTotalElements());
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to search users", ex);
        throw new TechnicalManagementException("An error occurs while trying to search users", ex);
    }
}
Also used : BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) Page(io.gravitee.common.data.domain.Page) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) LoggerFactory(org.slf4j.LoggerFactory) MembershipRepository(io.gravitee.repository.management.api.MembershipRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) SocialIdentityProviderEntity(io.gravitee.rest.api.model.configuration.identity.SocialIdentityProviderEntity) RoleScope(io.gravitee.rest.api.model.permissions.RoleScope) StringUtils(org.apache.commons.lang3.StringUtils) UPDATE(io.gravitee.rest.api.model.permissions.RolePermissionAction.UPDATE) IdentityProviderService(io.gravitee.rest.api.service.configuration.identity.IdentityProviderService) TemplateEngine(io.gravitee.el.TemplateEngine) Algorithm(com.auth0.jwt.algorithms.Algorithm) AuditQuery(io.gravitee.rest.api.model.audit.AuditQuery) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) RoleMappingEntity(io.gravitee.rest.api.model.configuration.identity.RoleMappingEntity) Duration(java.time.Duration) PortalHook(io.gravitee.rest.api.service.notification.PortalHook) GroupMappingEntity(io.gravitee.rest.api.model.configuration.identity.GroupMappingEntity) Collectors.toSet(java.util.stream.Collectors.toSet) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) RolePermissionAction(io.gravitee.rest.api.model.permissions.RolePermissionAction) JsonPathFunction(io.gravitee.el.spel.function.json.JsonPathFunction) Instant(java.time.Instant) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) Collectors(java.util.stream.Collectors) Key(io.gravitee.rest.api.model.parameters.Key) NotificationParamsBuilder(io.gravitee.rest.api.service.notification.NotificationParamsBuilder) EmailNotificationBuilder(io.gravitee.rest.api.service.builder.EmailNotificationBuilder) UrlSanitizerUtils(io.gravitee.rest.api.service.sanitizer.UrlSanitizerUtils) DatatypeConverter(javax.xml.bind.DatatypeConverter) AuditEntity(io.gravitee.rest.api.model.audit.AuditEntity) RolePermission(io.gravitee.rest.api.model.permissions.RolePermission) SearchEngineService(io.gravitee.rest.api.service.search.SearchEngineService) JWT(com.auth0.jwt.JWT) io.gravitee.rest.api.service(io.gravitee.rest.api.service) java.util(java.util) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Pageable(io.gravitee.rest.api.model.common.Pageable) GraviteeContext(io.gravitee.rest.api.service.common.GraviteeContext) DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER(io.gravitee.rest.api.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_EMAIL_REGISTRATION_EXPIRE_AFTER) InitializingBean(org.springframework.beans.factory.InitializingBean) Value(org.springframework.beans.factory.annotation.Value) JWTVerifier(com.auth0.jwt.JWTVerifier) ReadContext(com.jayway.jsonpath.ReadContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) UserRepository(io.gravitee.repository.management.api.UserRepository) Claims(io.gravitee.rest.api.service.common.JWTHelper.Claims) UserStatus(io.gravitee.repository.management.model.UserStatus) io.gravitee.rest.api.model(io.gravitee.rest.api.model) Membership(io.gravitee.repository.management.model.Membership) Query(io.gravitee.rest.api.service.search.query.Query) UuidString(io.gravitee.rest.api.service.common.UuidString) Logger(org.slf4j.Logger) ParameterReferenceType(io.gravitee.rest.api.model.parameters.ParameterReferenceType) JsonPath(com.jayway.jsonpath.JsonPath) Maps(io.gravitee.common.util.Maps) DEFAULT_JWT_ISSUER(io.gravitee.rest.api.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_ISSUER) MetadataPage(io.gravitee.common.data.domain.MetadataPage) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) USER(io.gravitee.repository.management.model.Audit.AuditProperties.USER) ChronoUnit(java.time.temporal.ChronoUnit) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) io.gravitee.rest.api.service.exceptions(io.gravitee.rest.api.service.exceptions) UserCriteria(io.gravitee.repository.management.api.search.UserCriteria) User(io.gravitee.repository.management.model.User) ACTION(io.gravitee.rest.api.service.common.JWTHelper.ACTION) QueryBuilder(io.gravitee.rest.api.service.search.query.QueryBuilder) SearchResult(io.gravitee.rest.api.service.impl.search.SearchResult) User(io.gravitee.repository.management.model.User) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) UserCriteria(io.gravitee.repository.management.api.search.UserCriteria) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder) NotificationParamsBuilder(io.gravitee.rest.api.service.notification.NotificationParamsBuilder) EmailNotificationBuilder(io.gravitee.rest.api.service.builder.EmailNotificationBuilder) QueryBuilder(io.gravitee.rest.api.service.search.query.QueryBuilder) Page(io.gravitee.common.data.domain.Page) MetadataPage(io.gravitee.common.data.domain.MetadataPage) PageableBuilder(io.gravitee.repository.management.api.search.builder.PageableBuilder)

Aggregations

Pageable (io.gravitee.rest.api.model.common.Pageable)3 Page (io.gravitee.common.data.domain.Page)2 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 PageableBuilder (io.gravitee.repository.management.api.search.builder.PageableBuilder)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 JWT (com.auth0.jwt.JWT)1 JWTVerifier (com.auth0.jwt.JWTVerifier)1 Algorithm (com.auth0.jwt.algorithms.Algorithm)1 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1 JsonPath (com.jayway.jsonpath.JsonPath)1 ReadContext (com.jayway.jsonpath.ReadContext)1 MetadataPage (io.gravitee.common.data.domain.MetadataPage)1 Maps (io.gravitee.common.util.Maps)1 TemplateEngine (io.gravitee.el.TemplateEngine)1 JsonPathFunction (io.gravitee.el.spel.function.json.JsonPathFunction)1 MembershipRepository (io.gravitee.repository.management.api.MembershipRepository)1 UserRepository (io.gravitee.repository.management.api.UserRepository)1 UserCriteria (io.gravitee.repository.management.api.search.UserCriteria)1