Search in sources :

Example 21 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean 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 22 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class JpaStorage method getApiRegistry.

/**
 * {@inheritDoc}
 */
@Override
public ApiRegistryBean getApiRegistry(String organizationId, String clientId, String version) throws StorageException {
    ApiRegistryBean rval = new ApiRegistryBean();
    try {
        EntityManager entityManager = getActiveEntityManager();
        String jpql = "SELECT c from ContractBean c " + "  JOIN c.client clientv " + "  JOIN clientv.client client " + "  JOIN client.organization aorg" + " WHERE client.id = :clientId " + "   AND aorg.id = :orgId " + "   AND clientv.version = :version " + " ORDER BY c.id ASC";
        TypedQuery<ContractBean> query = entityManager.createQuery(jpql, ContractBean.class).setParameter("orgId", organizationId).setParameter("clientId", clientId).setParameter("version", version);
        List<ContractBean> contracts = query.getResultList();
        for (ContractBean contractBean : contracts) {
            ApiVersionBean svb = contractBean.getApi();
            ApiBean api = svb.getApi();
            PlanBean plan = contractBean.getPlan().getPlan();
            OrganizationBean apiOrg = api.getOrganization();
            ApiEntryBean entry = new ApiEntryBean();
            entry.setApiId(api.getId());
            entry.setApiName(api.getName());
            entry.setApiOrgId(apiOrg.getId());
            entry.setApiOrgName(apiOrg.getName());
            entry.setApiVersion(svb.getVersion());
            entry.setPlanId(plan.getId());
            entry.setPlanName(plan.getName());
            entry.setPlanVersion(contractBean.getPlan().getVersion());
            Set<ApiGatewayBean> gateways = svb.getGateways();
            if (gateways != null && !gateways.isEmpty()) {
                ApiGatewayBean sgb = gateways.iterator().next();
                entry.setGatewayId(sgb.getGatewayId());
            }
            rval.getApis().add(entry);
        }
    } catch (Throwable t) {
        LOGGER.error(t.getMessage(), t);
        throw new StorageException(t);
    }
    return rval;
}
Also used : ApiRegistryBean(io.apiman.manager.api.beans.summary.ApiRegistryBean) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) EntityManager(javax.persistence.EntityManager) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) ApiEntryBean(io.apiman.manager.api.beans.summary.ApiEntryBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 23 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class JpaStorage method getContracts.

/**
 * {@inheritDoc}
 */
@Override
public List<ContractSummaryBean> getContracts(String organizationId, String apiId, String version, int page, int pageSize) throws StorageException {
    int start = (page - 1) * pageSize;
    try {
        EntityManager entityManager = getActiveEntityManager();
        String jpql = "SELECT c from ContractBean c " + "  JOIN c.api apiv " + "  JOIN apiv.api api " + "  JOIN c.client clientv " + "  JOIN clientv.client client " + "  JOIN api.organization sorg" + "  JOIN client.organization aorg" + " WHERE api.id = :apiId " + "   AND sorg.id = :orgId " + "   AND apiv.version = :version " + " ORDER BY sorg.id, api.id ASC";
        Query query = entityManager.createQuery(jpql);
        query.setParameter("orgId", organizationId);
        query.setParameter("apiId", apiId);
        query.setParameter("version", version);
        query.setFirstResult(start);
        query.setMaxResults(pageSize);
        List<ContractBean> contracts = query.getResultList();
        List<ContractSummaryBean> rval = new ArrayList<>(contracts.size());
        for (ContractBean contractBean : contracts) {
            ClientBean client = contractBean.getClient().getClient();
            ApiBean api = contractBean.getApi().getApi();
            PlanBean plan = contractBean.getPlan().getPlan();
            OrganizationBean clientOrg = entityManager.find(OrganizationBean.class, client.getOrganization().getId());
            OrganizationBean apiOrg = entityManager.find(OrganizationBean.class, api.getOrganization().getId());
            ContractSummaryBean csb = new ContractSummaryBean();
            csb.setStatus(contractBean.getStatus());
            csb.setClientId(client.getId());
            csb.setClientOrganizationId(client.getOrganization().getId());
            csb.setClientOrganizationName(clientOrg.getName());
            csb.setClientName(client.getName());
            csb.setClientVersion(contractBean.getClient().getVersion());
            csb.setContractId(contractBean.getId());
            csb.setCreatedOn(contractBean.getCreatedOn());
            csb.setPlanId(plan.getId());
            csb.setPlanName(plan.getName());
            csb.setPlanVersion(contractBean.getPlan().getVersion());
            csb.setApiDescription(api.getDescription());
            csb.setApiId(api.getId());
            csb.setApiName(api.getName());
            csb.setApiOrganizationId(apiOrg.getId());
            csb.setApiOrganizationName(apiOrg.getName());
            csb.setApiVersion(contractBean.getApi().getVersion());
            rval.add(csb);
        }
        return rval;
    } catch (Throwable t) {
        LOGGER.error(t.getMessage(), t);
        throw new StorageException(t);
    }
}
Also used : Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) ArrayList(java.util.ArrayList) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) PermissionConstraint(io.apiman.manager.api.beans.idm.PermissionConstraint) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) EntityManager(javax.persistence.EntityManager) ContractSummaryBean(io.apiman.manager.api.beans.summary.ContractSummaryBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Example 24 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class JpaStorage method findClients.

/**
 * {@inheritDoc}
 */
@Override
public SearchResultsBean<ClientSummaryBean> findClients(SearchCriteriaBean criteria, PermissionConstraint permissionConstraint) throws StorageException {
    // If unconstrained, do nothing.
    Consumer<CriteriaBuilder<ClientBean>> constraintFunc = builder -> {
    };
    if (permissionConstraint.isConstrained()) {
        constraintFunc = (builder) -> builder.where("organization.id").in(permissionConstraint.getPermittedOrgs());
    }
    SearchResultsBean<ClientBean> result = find(criteria, List.of(new OrderByBean(true, ClientBean_.ID), new OrderByBean(true, "organization.id")), constraintFunc, ClientBean.class, "client", true);
    SearchResultsBean<ClientSummaryBean> rval = new SearchResultsBean<>();
    rval.setTotalSize(result.getTotalSize());
    List<ClientBean> beans = result.getBeans();
    rval.setBeans(new ArrayList<>(beans.size()));
    for (ClientBean client : beans) {
        ClientSummaryBean summary = new ClientSummaryBean();
        OrganizationBean organization = client.getOrganization();
        summary.setId(client.getId());
        summary.setName(client.getName());
        summary.setDescription(client.getDescription());
        summary.setImage(client.getImage());
        // TODO find the number of contracts - probably need native SQL for that
        summary.setNumContracts(0);
        summary.setOrganizationId(client.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) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) ClientSummaryBean(io.apiman.manager.api.beans.summary.ClientSummaryBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) OrderByBean(io.apiman.manager.api.beans.search.OrderByBean)

Example 25 with OrganizationBean

use of io.apiman.manager.api.beans.orgs.OrganizationBean in project apiman by apiman.

the class JpaStorage method getPlansInOrgs.

/**
 * {@inheritDoc}
 */
@Override
public List<PlanSummaryBean> getPlansInOrgs(Set<String> orgIds) throws StorageException {
    List<PlanSummaryBean> rval = new ArrayList<>();
    if (orgIds == null || orgIds.isEmpty()) {
        return rval;
    }
    try {
        EntityManager entityManager = getActiveEntityManager();
        String jpql = "SELECT p FROM PlanBean p JOIN p.organization o WHERE o.id IN :orgs ORDER BY p.id ASC";
        TypedQuery<PlanBean> query = entityManager.createQuery(jpql, PlanBean.class).setParameter("orgs", orgIds).setMaxResults(500);
        List<PlanBean> qr = query.getResultList();
        for (PlanBean bean : qr) {
            PlanSummaryBean summary = new PlanSummaryBean();
            summary.setId(bean.getId());
            summary.setName(bean.getName());
            summary.setDescription(bean.getDescription());
            OrganizationBean org = bean.getOrganization();
            summary.setOrganizationId(org.getId());
            summary.setOrganizationName(org.getName());
            rval.add(summary);
        }
        return rval;
    } catch (Throwable t) {
        LOGGER.error(t.getMessage(), t);
        throw new StorageException(t);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ArrayList(java.util.ArrayList) 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) StorageException(io.apiman.manager.api.core.exceptions.StorageException)

Aggregations

OrganizationBean (io.apiman.manager.api.beans.orgs.OrganizationBean)49 StorageException (io.apiman.manager.api.core.exceptions.StorageException)20 ContractBean (io.apiman.manager.api.beans.contracts.ContractBean)14 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)13 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)13 NewOrganizationBean (io.apiman.manager.api.beans.orgs.NewOrganizationBean)13 PlanBean (io.apiman.manager.api.beans.plans.PlanBean)13 IOException (java.io.IOException)13 ApiPlanBean (io.apiman.manager.api.beans.apis.ApiPlanBean)12 ClientBean (io.apiman.manager.api.beans.clients.ClientBean)12 UpdateOrganizationBean (io.apiman.manager.api.beans.orgs.UpdateOrganizationBean)12 PlanVersionBean (io.apiman.manager.api.beans.plans.PlanVersionBean)10 Date (java.util.Date)10 ClientVersionBean (io.apiman.manager.api.beans.clients.ClientVersionBean)9 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)9 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)8 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)8 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)8 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)8 EntityManager (javax.persistence.EntityManager)8