@Override
    public ApiRegistryBean getApiRegistry(String organizationId, String clientId, String version)
            throws StorageException {
        ApiRegistryBean rval = new ApiRegistryBean();

        beginTx();
        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";
            Query query = entityManager.createQuery(jpql);
            query.setParameter("orgId", organizationId);
            query.setParameter("clientId", clientId);
            query.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);
        } finally {
            rollbackTx();
        }
        return rval;
    }
@ Override public ApiRegistryBean getApiRegistry ( String organizationId , String clientId , String version ) throws StorageException { ApiRegistryBean rval = new ApiRegistryBean ( ) ; beginTx ( ) ; 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" ; Query query = entityManager . createQuery ( jpql ) ; query . setParameter ( "orgId" , organizationId ) ; query . setParameter ( "clientId" , clientId ) ; query . 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 ) ; } finally { rollbackTx ( ) ; } return rval ; }
@see io.apiman.manager.api.core.IStorageQuery#getApiRegistry(java.lang.String, java.lang.String, java.lang.String)