Search in sources :

Example 1 with ApiVersionSummaryBean

use of io.apiman.manager.api.beans.summary.ApiVersionSummaryBean in project apiman by apiman.

the class JpaStorage method getApiVersions.

// TODO(msavy): rewrite using projection
/**
 * {@inheritDoc}
 */
@Override
public List<ApiVersionSummaryBean> getApiVersions(String orgId, String apiId) throws StorageException {
    try {
        EntityManager entityManager = getActiveEntityManager();
        String jpql = "SELECT v " + "  FROM ApiVersionBean v" + "  JOIN v.api s" + "  JOIN s.organization o" + " WHERE o.id = :orgId" + "  AND s.id = :apiId" + " ORDER BY v.createdOn DESC";
        TypedQuery<ApiVersionBean> query = entityManager.createQuery(jpql, ApiVersionBean.class).setMaxResults(500).setParameter("orgId", orgId).setParameter("apiId", apiId);
        List<ApiVersionBean> apiVersions = query.getResultList();
        return apiVersions.stream().map(e -> apiMapper.toSummary(e)).collect(Collectors.toList());
    } catch (Throwable t) {
        LOGGER.error(t.getMessage(), t);
        throw new StorageException(t);
    }
}
Also used : 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) EntityManager(javax.persistence.EntityManager) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 2 with ApiVersionSummaryBean

use of io.apiman.manager.api.beans.summary.ApiVersionSummaryBean in project apiman by apiman.

the class EsStorage method getApiVersions.

/**
 * @see io.apiman.manager.api.core.IStorageQuery#getApiVersions(java.lang.String, java.lang.String)
 */
@Override
@SuppressWarnings("nls")
public List<ApiVersionSummaryBean> getApiVersions(String organizationId, String apiId) throws StorageException {
    BoolQueryBuilder query = QueryBuilders.boolQuery();
    List<QueryBuilder> filter = query.filter();
    filter.add(QueryBuilders.termQuery("organizationId", organizationId));
    filter.add(QueryBuilders.termQuery("apiId", apiId));
    SearchSourceBuilder builder = new SearchSourceBuilder().sort(new FieldSortBuilder("createdOn").order(SortOrder.ASC)).query(query).size(500);
    List<SearchHit> hits = listEntities(INDEX_MANAGER_POSTFIX_API_VERSION, builder);
    List<ApiVersionSummaryBean> rval = new ArrayList<>(hits.size());
    for (SearchHit hit : hits) {
        ApiVersionSummaryBean bean = EsMarshalling.unmarshallApiVersionSummary(hit.getSourceAsMap());
        rval.add(bean);
    }
    return rval;
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ArrayList(java.util.ArrayList) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) ApiVersionSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionSummaryBean) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 3 with ApiVersionSummaryBean

use of io.apiman.manager.api.beans.summary.ApiVersionSummaryBean in project apiman by apiman.

the class EsMarshalling method unmarshallApiVersionSummary.

/**
 * Unmarshals the given map source into a bean.
 * @param source the source
 * @return the API version summary
 */
public static ApiVersionSummaryBean unmarshallApiVersionSummary(Map<String, Object> source) {
    if (source == null) {
        return null;
    }
    ApiVersionSummaryBean bean = new ApiVersionSummaryBean();
    bean.setDescription(asString(source.get("apiDescription")));
    bean.setId(asString(source.get("apiId")));
    bean.setName(asString(source.get("apiName")));
    bean.setOrganizationId(asString(source.get("organizationId")));
    bean.setOrganizationName(asString(source.get("organizationName")));
    bean.setStatus(asEnum(source.get("status"), ApiStatus.class));
    bean.setVersion(asString(source.get("version")));
    bean.setPublicAPI(asBoolean(source.get("publicAPI")));
    postMarshall(bean);
    return bean;
}
Also used : ApiStatus(io.apiman.manager.api.beans.apis.ApiStatus) ApiVersionSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionSummaryBean)

Aggregations

ApiVersionSummaryBean (io.apiman.manager.api.beans.summary.ApiVersionSummaryBean)3 ApiStatus (io.apiman.manager.api.beans.apis.ApiStatus)2 ArrayList (java.util.ArrayList)2 CriteriaBuilder (com.blazebit.persistence.CriteriaBuilder)1 DeleteCriteriaBuilder (com.blazebit.persistence.DeleteCriteriaBuilder)1 ApimanLoggerFactory (io.apiman.common.logging.ApimanLoggerFactory)1 IApimanLogger (io.apiman.common.logging.IApimanLogger)1 DataEncryptionContext (io.apiman.common.util.crypt.DataEncryptionContext)1 IDataEncrypter (io.apiman.common.util.crypt.IDataEncrypter)1 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)1 ApiDefinitionBean (io.apiman.manager.api.beans.apis.ApiDefinitionBean)1 ApiGatewayBean (io.apiman.manager.api.beans.apis.ApiGatewayBean)1 ApiPlanBean (io.apiman.manager.api.beans.apis.ApiPlanBean)1 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)1 AuditEntityType (io.apiman.manager.api.beans.audit.AuditEntityType)1 AuditEntryBean (io.apiman.manager.api.beans.audit.AuditEntryBean)1 AuditEntryBean_ (io.apiman.manager.api.beans.audit.AuditEntryBean_)1 ClientBean (io.apiman.manager.api.beans.clients.ClientBean)1 ClientBean_ (io.apiman.manager.api.beans.clients.ClientBean_)1 ClientStatus (io.apiman.manager.api.beans.clients.ClientStatus)1