Search in sources :

Example 1 with OrderByBean

use of io.apiman.manager.api.beans.search.OrderByBean in project apiman by apiman.

the class AbstractJpaStorage method applySearchCriteriaToQuery.

/**
 * Applies the criteria found in the {@link SearchCriteriaBean} to the JPA query.
 * @param criteria
 * @param builder
 * @param query
 * @param from
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected <T> void applySearchCriteriaToQuery(SearchCriteriaBean criteria, CriteriaBuilder builder, CriteriaQuery<?> query, Root<T> from, boolean countOnly) {
    List<SearchCriteriaFilterBean> filters = criteria.getFilters();
    if (filters != null && !filters.isEmpty()) {
        List<Predicate> predicates = new ArrayList<>();
        for (SearchCriteriaFilterBean filter : filters) {
            if (filter.getOperator() == SearchCriteriaFilterOperator.eq) {
                Path<Object> path = from.get(filter.getName());
                Class<?> pathc = path.getJavaType();
                if (pathc.isAssignableFrom(String.class)) {
                    predicates.add(builder.equal(path, filter.getValue()));
                } else if (pathc.isEnum()) {
                    predicates.add(builder.equal(path, Enum.valueOf((Class) pathc, filter.getValue())));
                }
            } else if (filter.getOperator() == SearchCriteriaFilterOperator.bool_eq) {
                predicates.add(builder.equal(from.<Boolean>get(filter.getName()), Boolean.valueOf(filter.getValue())));
            } else if (filter.getOperator() == SearchCriteriaFilterOperator.gt) {
                predicates.add(builder.greaterThan(from.<Long>get(filter.getName()), new Long(filter.getValue())));
            } else if (filter.getOperator() == SearchCriteriaFilterOperator.gte) {
                predicates.add(builder.greaterThanOrEqualTo(from.<Long>get(filter.getName()), new Long(filter.getValue())));
            } else if (filter.getOperator() == SearchCriteriaFilterOperator.lt) {
                predicates.add(builder.lessThan(from.<Long>get(filter.getName()), new Long(filter.getValue())));
            } else if (filter.getOperator() == SearchCriteriaFilterOperator.lte) {
                predicates.add(builder.lessThanOrEqualTo(from.<Long>get(filter.getName()), new Long(filter.getValue())));
            } else if (filter.getOperator() == SearchCriteriaFilterOperator.neq) {
                predicates.add(builder.notEqual(from.get(filter.getName()), filter.getValue()));
            } else if (filter.getOperator() == SearchCriteriaFilterOperator.like) {
                predicates.add(builder.like(builder.upper(from.<String>get(filter.getName())), filter.getValue().toUpperCase().replace('*', '%')));
            }
        }
        query.where(predicates.toArray(new Predicate[predicates.size()]));
    }
    OrderByBean orderBy = criteria.getOrderBy();
    if (orderBy != null && !countOnly) {
        if (orderBy.isAscending()) {
            query.orderBy(builder.asc(from.get(orderBy.getName())));
        } else {
            query.orderBy(builder.desc(from.get(orderBy.getName())));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SearchCriteriaFilterBean(io.apiman.manager.api.beans.search.SearchCriteriaFilterBean) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean) Predicate(javax.persistence.criteria.Predicate)

Example 2 with OrderByBean

use of io.apiman.manager.api.beans.search.OrderByBean in project apiman by apiman.

the class EsStorage method find.

/**
 * Finds entities using a generic search criteria bean.
 * @param criteria
 * @param type
 * @param unmarshaller
 * @throws StorageException
 */
private <T> SearchResultsBean<T> find(SearchCriteriaBean criteria, String type, IUnmarshaller<T> unmarshaller) throws StorageException {
    try {
        SearchResultsBean<T> rval = new SearchResultsBean<>();
        // Set some default in the case that paging information was not included in the request.
        PagingBean paging = criteria.getPaging();
        if (paging == null) {
            paging = new PagingBean();
            paging.setPage(1);
            paging.setPageSize(20);
        }
        int page = paging.getPage();
        int pageSize = paging.getPageSize();
        int start = (page - 1) * pageSize;
        SearchSourceBuilder builder = new SearchSourceBuilder().size(pageSize).from(start).fetchSource(true);
        // Sort order
        OrderByBean orderBy = criteria.getOrderBy();
        if (orderBy != null) {
            String name = orderBy.getName();
            // Get the index definition so that we can see whether a '.keyword' is available. If so, use it.
            EsIndexProperties esIndex = getEsIndices().get(type);
            if (esIndex.hasProperty(name) && esIndex.getProperty(name).isKeywordMultiField()) {
                name = name + ".keyword";
            }
            if (orderBy.isAscending()) {
                builder.sort(name, SortOrder.ASC);
            } else {
                builder.sort(name, SortOrder.DESC);
            }
        }
        // Now process the filter criteria
        List<SearchCriteriaFilterBean> filters = criteria.getFilters();
        QueryBuilder q = null;
        if (filters != null && !filters.isEmpty()) {
            BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
            List<QueryBuilder> andFilter = boolQuery.filter();
            int filterCount = 0;
            for (SearchCriteriaFilterBean filter : filters) {
                String propertyName = filter.getName();
                if (filter.getOperator() == SearchCriteriaFilterOperator.eq) {
                    andFilter.add(QueryBuilders.termQuery(propertyName, filter.getValue()));
                    filterCount++;
                } else if (filter.getOperator() == SearchCriteriaFilterOperator.like) {
                    q = QueryBuilders.wildcardQuery(propertyName, filter.getValue().toLowerCase().replace('%', '*'));
                } else if (filter.getOperator() == SearchCriteriaFilterOperator.bool_eq) {
                    // $NON-NLS-1$
                    andFilter.add(QueryBuilders.termQuery(propertyName, "true".equals(filter.getValue())));
                    filterCount++;
                }
            // TODO implement the other filter operators here!
            }
            if (filterCount > 0) {
                q = boolQuery;
            }
        }
        builder.query(q);
        String fullIndexName = getFullIndexName(type);
        SearchResponse response = getClient().search(new SearchRequest(fullIndexName).source(builder), RequestOptions.DEFAULT);
        SearchHits thehits = response.getHits();
        rval.setTotalSize((int) thehits.getTotalHits().value);
        for (SearchHit hit : thehits.getHits()) {
            Map<String, Object> sourceAsMap = hit.getSourceAsMap();
            T bean = unmarshaller.unmarshal(sourceAsMap);
            rval.getBeans().add(bean);
        }
        return rval;
    } catch (Exception e) {
        throw new StorageException(e);
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) SearchHit(org.elasticsearch.search.SearchHit) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) IOException(java.io.IOException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) EsIndexProperties(io.apiman.common.es.util.builder.index.EsIndexProperties) INDEX_MANAGER_POSTFIX_CONTRACT(io.apiman.common.es.util.EsConstants.INDEX_MANAGER_POSTFIX_CONTRACT) INDEX_MANAGER_POSTFIX_CLIENT(io.apiman.common.es.util.EsConstants.INDEX_MANAGER_POSTFIX_CLIENT) PagingBean(io.apiman.manager.api.beans.search.PagingBean) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) SearchHits(org.elasticsearch.search.SearchHits) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean) SearchCriteriaFilterBean(io.apiman.manager.api.beans.search.SearchCriteriaFilterBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 3 with OrderByBean

use of io.apiman.manager.api.beans.search.OrderByBean in project apiman by apiman.

the class JpaStorage method findOrganizations.

/**
 * {@inheritDoc}
 */
@Override
public SearchResultsBean<OrganizationSummaryBean> findOrganizations(SearchCriteriaBean criteria, PermissionConstraint permissionConstraint) throws StorageException {
    Consumer<CriteriaBuilder<OrganizationBean>> constraintFunc = builder -> {
    };
    if (permissionConstraint.isConstrained()) {
        // With constraint, first allow the user's explicitly permitted orgs, plus orgs with discoverable APIs.
        constraintFunc = (builder) -> builder.whereOr().where(OrganizationBean_.ID).in(permissionConstraint.getPermittedOrgs()).where("org.id").in().from(DiscoverabilityEntity.class, "d").select("d.orgId").where("d.discoverability").isNotNull().where("d.discoverability").in(permissionConstraint.getAllowedDiscoverabilities()).end().endOr();
    }
    SearchResultsBean<OrganizationBean> orgs = find(criteria, List.of(new OrderByBean(true, OrganizationBean_.ID)), constraintFunc, OrganizationBean.class, "org", true);
    SearchResultsBean<OrganizationSummaryBean> rval = new SearchResultsBean<>();
    rval.setTotalSize(orgs.getTotalSize());
    List<OrganizationBean> beans = orgs.getBeans();
    for (OrganizationBean bean : beans) {
        OrganizationSummaryBean osb = new OrganizationSummaryBean();
        osb.setId(bean.getId());
        osb.setName(bean.getName());
        osb.setDescription(bean.getDescription());
        rval.getBeans().add(osb);
    }
    return rval;
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) DeleteCriteriaBuilder(com.blazebit.persistence.DeleteCriteriaBuilder) PermissionConstraint(io.apiman.manager.api.beans.idm.PermissionConstraint) RoleBean_(io.apiman.manager.api.beans.idm.RoleBean_) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) ApiPlanSummaryBean(io.apiman.manager.api.beans.summary.ApiPlanSummaryBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) NoResultException(javax.persistence.NoResultException) IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) ApiDefinitionBean(io.apiman.manager.api.beans.apis.ApiDefinitionBean) UserBean(io.apiman.manager.api.beans.idm.UserBean) SearchCriteriaFilterOperator(io.apiman.manager.api.beans.search.SearchCriteriaFilterOperator) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) DeveloperBean(io.apiman.manager.api.beans.developers.DeveloperBean) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) PagingBean(io.apiman.manager.api.beans.search.PagingBean) Map(java.util.Map) DiscoverabilityEntity(io.apiman.manager.api.beans.idm.DiscoverabilityEntity) ApimanLoggerFactory(io.apiman.common.logging.ApimanLoggerFactory) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) GatewayType(io.apiman.manager.api.beans.gateways.GatewayType) ApiEntryBean(io.apiman.manager.api.beans.summary.ApiEntryBean) Transactional(javax.transaction.Transactional) Set(java.util.Set) UserBean_(io.apiman.manager.api.beans.idm.UserBean_) GatewaySummaryBean(io.apiman.manager.api.beans.summary.GatewaySummaryBean) PermissionBean(io.apiman.manager.api.beans.idm.PermissionBean) PluginSummaryBean(io.apiman.manager.api.beans.summary.PluginSummaryBean) Collectors(java.util.stream.Collectors) ApiVersionSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionSummaryBean) ApiSummaryBean(io.apiman.manager.api.beans.summary.ApiSummaryBean) ClientSummaryBean(io.apiman.manager.api.beans.summary.ClientSummaryBean) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Query(javax.persistence.Query) IApimanLogger(io.apiman.common.logging.IApimanLogger) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) OrganizationBean_(io.apiman.manager.api.beans.orgs.OrganizationBean_) AuditEntryBean(io.apiman.manager.api.beans.audit.AuditEntryBean) RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) PostConstruct(javax.annotation.PostConstruct) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ClientBean_(io.apiman.manager.api.beans.clients.ClientBean_) PermissionType(io.apiman.manager.api.beans.idm.PermissionType) OrganizationSummaryBean(io.apiman.manager.api.beans.summary.OrganizationSummaryBean) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) DiscoverabilityLevel(io.apiman.manager.api.beans.idm.DiscoverabilityLevel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PluginBean(io.apiman.manager.api.beans.plugins.PluginBean) Alternative(javax.enterprise.inject.Alternative) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) PlanSummaryBean(io.apiman.manager.api.beans.summary.PlanSummaryBean) ApiStatus(io.apiman.manager.api.beans.apis.ApiStatus) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) TypedQuery(javax.persistence.TypedQuery) AuditEntryBean_(io.apiman.manager.api.beans.audit.AuditEntryBean_) ArrayList(java.util.ArrayList) AuditEntityType(io.apiman.manager.api.beans.audit.AuditEntityType) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext) PlanBean_(io.apiman.manager.api.beans.plans.PlanBean_) DeleteCriteriaBuilder(com.blazebit.persistence.DeleteCriteriaBuilder) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) QualifiedType(org.jdbi.v3.core.qualifier.QualifiedType) PolicyTemplateUtil(io.apiman.manager.api.core.util.PolicyTemplateUtil) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean) MetadataBean(io.apiman.manager.api.beans.system.MetadataBean) ClientVersionSummaryBean(io.apiman.manager.api.beans.summary.ClientVersionSummaryBean) Iterator(java.util.Iterator) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) ClientStatus(io.apiman.manager.api.beans.clients.ClientStatus) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) ContractSummaryBean(io.apiman.manager.api.beans.summary.ContractSummaryBean) ApiMapper(io.apiman.manager.api.beans.summary.mappers.ApiMapper) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) IStorage(io.apiman.manager.api.core.IStorage) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) ApiRegistryBean(io.apiman.manager.api.beans.summary.ApiRegistryBean) PolicyBean_(io.apiman.manager.api.beans.policies.PolicyBean_) Consumer(java.util.function.Consumer) DownloadBean(io.apiman.manager.api.beans.download.DownloadBean) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PolicyDefinitionSummaryBean(io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean) PlanStatus(io.apiman.manager.api.beans.plans.PlanStatus) Collections(java.util.Collections) InputStream(java.io.InputStream) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean) OrganizationSummaryBean(io.apiman.manager.api.beans.summary.OrganizationSummaryBean)

Example 4 with OrderByBean

use of io.apiman.manager.api.beans.search.OrderByBean in project apiman by apiman.

the class JpaStorage method findPlans.

/**
 * {@inheritDoc}
 */
@Override
public SearchResultsBean<PlanSummaryBean> findPlans(String organizationId, SearchCriteriaBean criteria, PermissionConstraint permissionConstraint) throws StorageException {
    Consumer<CriteriaBuilder<PlanBean>> constraintFunc = builder -> {
    };
    if (permissionConstraint.isConstrained()) {
        constraintFunc = builder -> builder.whereOr().where("plan.organization.id").in(permissionConstraint.getPermittedOrgs()).where("plan.id").in().from(DiscoverabilityEntity.class, "d").select("d.planId").where("d.orgId").eq(organizationId).where("d.planId").isNotNull().where("d.discoverability").in(permissionConstraint.getAllowedDiscoverabilities()).end().endOr();
    }
    SearchResultsBean<PlanBean> result = find(criteria, List.of(new OrderByBean(true, PlanBean_.ID), new OrderByBean(true, "organization.id")), constraintFunc, PlanBean.class, "plan", true);
    // TODO(msavy): replace with projection or mapping
    SearchResultsBean<PlanSummaryBean> rval = new SearchResultsBean<>();
    rval.setTotalSize(result.getTotalSize());
    List<PlanBean> plans = result.getBeans();
    rval.setBeans(new ArrayList<>(plans.size()));
    for (PlanBean plan : plans) {
        PlanSummaryBean summary = new PlanSummaryBean();
        OrganizationBean organization = plan.getOrganization();
        summary.setId(plan.getId());
        summary.setName(plan.getName());
        summary.setDescription(plan.getDescription());
        summary.setOrganizationId(plan.getOrganization().getId());
        summary.setOrganizationName(organization.getName());
        rval.getBeans().add(summary);
    }
    return rval;
}
Also used : CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) DeleteCriteriaBuilder(com.blazebit.persistence.DeleteCriteriaBuilder) PermissionConstraint(io.apiman.manager.api.beans.idm.PermissionConstraint) RoleBean_(io.apiman.manager.api.beans.idm.RoleBean_) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) ApiPlanSummaryBean(io.apiman.manager.api.beans.summary.ApiPlanSummaryBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) NoResultException(javax.persistence.NoResultException) IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) ApiDefinitionBean(io.apiman.manager.api.beans.apis.ApiDefinitionBean) UserBean(io.apiman.manager.api.beans.idm.UserBean) SearchCriteriaFilterOperator(io.apiman.manager.api.beans.search.SearchCriteriaFilterOperator) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) DeveloperBean(io.apiman.manager.api.beans.developers.DeveloperBean) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) CriteriaBuilder(com.blazebit.persistence.CriteriaBuilder) PagingBean(io.apiman.manager.api.beans.search.PagingBean) Map(java.util.Map) DiscoverabilityEntity(io.apiman.manager.api.beans.idm.DiscoverabilityEntity) ApimanLoggerFactory(io.apiman.common.logging.ApimanLoggerFactory) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) GatewayType(io.apiman.manager.api.beans.gateways.GatewayType) ApiEntryBean(io.apiman.manager.api.beans.summary.ApiEntryBean) Transactional(javax.transaction.Transactional) Set(java.util.Set) UserBean_(io.apiman.manager.api.beans.idm.UserBean_) GatewaySummaryBean(io.apiman.manager.api.beans.summary.GatewaySummaryBean) PermissionBean(io.apiman.manager.api.beans.idm.PermissionBean) PluginSummaryBean(io.apiman.manager.api.beans.summary.PluginSummaryBean) Collectors(java.util.stream.Collectors) ApiVersionSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionSummaryBean) ApiSummaryBean(io.apiman.manager.api.beans.summary.ApiSummaryBean) ClientSummaryBean(io.apiman.manager.api.beans.summary.ClientSummaryBean) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Query(javax.persistence.Query) IApimanLogger(io.apiman.common.logging.IApimanLogger) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) OrganizationBean_(io.apiman.manager.api.beans.orgs.OrganizationBean_) AuditEntryBean(io.apiman.manager.api.beans.audit.AuditEntryBean) RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) PostConstruct(javax.annotation.PostConstruct) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) ApplicationScoped(javax.enterprise.context.ApplicationScoped) ClientBean_(io.apiman.manager.api.beans.clients.ClientBean_) PermissionType(io.apiman.manager.api.beans.idm.PermissionType) OrganizationSummaryBean(io.apiman.manager.api.beans.summary.OrganizationSummaryBean) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) DiscoverabilityLevel(io.apiman.manager.api.beans.idm.DiscoverabilityLevel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PluginBean(io.apiman.manager.api.beans.plugins.PluginBean) Alternative(javax.enterprise.inject.Alternative) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) PlanSummaryBean(io.apiman.manager.api.beans.summary.PlanSummaryBean) ApiStatus(io.apiman.manager.api.beans.apis.ApiStatus) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) TypedQuery(javax.persistence.TypedQuery) AuditEntryBean_(io.apiman.manager.api.beans.audit.AuditEntryBean_) ArrayList(java.util.ArrayList) AuditEntityType(io.apiman.manager.api.beans.audit.AuditEntityType) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext) PlanBean_(io.apiman.manager.api.beans.plans.PlanBean_) DeleteCriteriaBuilder(com.blazebit.persistence.DeleteCriteriaBuilder) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) QualifiedType(org.jdbi.v3.core.qualifier.QualifiedType) PolicyTemplateUtil(io.apiman.manager.api.core.util.PolicyTemplateUtil) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean) MetadataBean(io.apiman.manager.api.beans.system.MetadataBean) ClientVersionSummaryBean(io.apiman.manager.api.beans.summary.ClientVersionSummaryBean) Iterator(java.util.Iterator) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) ClientStatus(io.apiman.manager.api.beans.clients.ClientStatus) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) ContractSummaryBean(io.apiman.manager.api.beans.summary.ContractSummaryBean) ApiMapper(io.apiman.manager.api.beans.summary.mappers.ApiMapper) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) IStorage(io.apiman.manager.api.core.IStorage) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) ApiRegistryBean(io.apiman.manager.api.beans.summary.ApiRegistryBean) PolicyBean_(io.apiman.manager.api.beans.policies.PolicyBean_) Consumer(java.util.function.Consumer) DownloadBean(io.apiman.manager.api.beans.download.DownloadBean) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PolicyDefinitionSummaryBean(io.apiman.manager.api.beans.summary.PolicyDefinitionSummaryBean) PlanStatus(io.apiman.manager.api.beans.plans.PlanStatus) Collections(java.util.Collections) InputStream(java.io.InputStream) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) ApiPlanSummaryBean(io.apiman.manager.api.beans.summary.ApiPlanSummaryBean) PlanSummaryBean(io.apiman.manager.api.beans.summary.PlanSummaryBean) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean)

Example 5 with OrderByBean

use of io.apiman.manager.api.beans.search.OrderByBean in project apiman by apiman.

the class JpaStorage method auditEntity.

/**
 * {@inheritDoc}
 */
@Override
public <T> SearchResultsBean<AuditEntryBean> auditEntity(String organizationId, String entityId, String entityVersion, Class<T> type, PagingBean paging) throws StorageException {
    SearchCriteriaBean criteria = new SearchCriteriaBean();
    if (paging != null) {
        criteria.setPaging(paging);
    } else {
        criteria.setPage(1);
        criteria.setPageSize(20);
    }
    criteria.setOrder("id", false);
    if (organizationId != null) {
        criteria.addFilter("organizationId", organizationId, SearchCriteriaFilterOperator.eq);
    }
    if (entityId != null) {
        criteria.addFilter("entityId", entityId, SearchCriteriaFilterOperator.eq);
    }
    if (entityVersion != null) {
        criteria.addFilter("entityVersion", entityVersion, SearchCriteriaFilterOperator.eq);
    }
    if (type != null) {
        AuditEntityType entityType = null;
        if (type == OrganizationBean.class) {
            entityType = AuditEntityType.Organization;
        } else if (type == ClientBean.class) {
            entityType = AuditEntityType.Client;
        } else if (type == ApiBean.class) {
            entityType = AuditEntityType.Api;
        } else if (type == PlanBean.class) {
            entityType = AuditEntityType.Plan;
        }
        if (entityType != null) {
            criteria.addFilter("entityType", entityType.name(), SearchCriteriaFilterOperator.eq);
        }
    }
    return find(criteria, List.of(new OrderByBean(true, AuditEntryBean_.ID)), AuditEntryBean.class, true);
}
Also used : AuditEntityType(io.apiman.manager.api.beans.audit.AuditEntityType) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean)

Aggregations

OrderByBean (io.apiman.manager.api.beans.search.OrderByBean)12 SearchCriteriaBean (io.apiman.manager.api.beans.search.SearchCriteriaBean)7 PagingBean (io.apiman.manager.api.beans.search.PagingBean)5 SearchResultsBean (io.apiman.manager.api.beans.search.SearchResultsBean)5 StorageException (io.apiman.manager.api.core.exceptions.StorageException)5 ApiPlanBean (io.apiman.manager.api.beans.apis.ApiPlanBean)4 AuditEntityType (io.apiman.manager.api.beans.audit.AuditEntityType)4 ClientBean (io.apiman.manager.api.beans.clients.ClientBean)4 PlanBean (io.apiman.manager.api.beans.plans.PlanBean)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)3 DeleteCriteriaBuilder (com.blazebit.persistence.DeleteCriteriaBuilder)3 ApimanLoggerFactory (io.apiman.common.logging.ApimanLoggerFactory)3 IApimanLogger (io.apiman.common.logging.IApimanLogger)3 DataEncryptionContext (io.apiman.common.util.crypt.DataEncryptionContext)3 IDataEncrypter (io.apiman.common.util.crypt.IDataEncrypter)3 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)3 ApiDefinitionBean (io.apiman.manager.api.beans.apis.ApiDefinitionBean)3 ApiGatewayBean (io.apiman.manager.api.beans.apis.ApiGatewayBean)3