use of io.apiman.manager.api.beans.summary.ApiEntryBean in project apiman by apiman.
the class OrganizationResourceImpl method getApiRegistry.
/**
* Gets the API registry.
* @param organizationId
* @param clientId
* @param version
* @throws ClientVersionNotFoundException
*/
private ApiRegistryBean getApiRegistry(String organizationId, String clientId, String version) throws ClientVersionNotFoundException {
// Try to get the client first - will throw a ClientVersionNotFoundException if not found.
ClientVersionBean clientVersion = getClientVersionInternal(organizationId, clientId, version);
Map<String, IGatewayLink> gatewayLinks = new HashMap<>();
Map<String, GatewayBean> gateways = new HashMap<>();
boolean txStarted = false;
try {
ApiRegistryBean apiRegistry = query.getApiRegistry(organizationId, clientId, version);
apiRegistry.setApiKey(clientVersion.getApikey());
List<ApiEntryBean> apis = apiRegistry.getApis();
storage.beginTx();
txStarted = true;
for (ApiEntryBean api : apis) {
String gatewayId = api.getGatewayId();
// Don't return the gateway id.
api.setGatewayId(null);
GatewayBean gateway = gateways.get(gatewayId);
if (gateway == null) {
gateway = storage.getGateway(gatewayId);
gateways.put(gatewayId, gateway);
}
IGatewayLink link = gatewayLinks.get(gatewayId);
if (link == null) {
link = gatewayLinkFactory.create(gateway);
gatewayLinks.put(gatewayId, link);
}
ApiEndpoint se = link.getApiEndpoint(api.getApiOrgId(), api.getApiId(), api.getApiVersion());
String apiEndpoint = se.getEndpoint();
api.setHttpEndpoint(apiEndpoint);
}
return apiRegistry;
} catch (StorageException | GatewayAuthenticationException e) {
throw new SystemErrorException(e);
} finally {
if (txStarted) {
storage.rollbackTx();
}
for (IGatewayLink link : gatewayLinks.values()) {
link.close();
}
}
}
use of io.apiman.manager.api.beans.summary.ApiEntryBean 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;
}
use of io.apiman.manager.api.beans.summary.ApiEntryBean in project apiman by apiman.
the class OrganizationService method getApiRegistry.
/**
* Gets the API registry.
*/
public ApiRegistryBean getApiRegistry(String organizationId, String clientId, String version) throws ClientVersionNotFoundException {
// Try to get the client first - will throw a ClientVersionNotFoundException if not found.
ClientVersionBean clientVersion = clientService.getClientVersion(organizationId, clientId, version);
// TODO need to be careful with null on setGatewayId below
Map<String, IGatewayLink> gatewayLinks = new HashMap<>();
Map<String, GatewayBean> gateways = new HashMap<>();
try {
ApiRegistryBean apiRegistry = query.getApiRegistry(organizationId, clientId, version);
apiRegistry.setApiKey(clientVersion.getApikey());
List<ApiEntryBean> apis = apiRegistry.getApis();
for (ApiEntryBean api : apis) {
String gatewayId = api.getGatewayId();
// Don't return the gateway id.
api.setGatewayId(null);
GatewayBean gateway = gateways.get(gatewayId);
if (gateway == null) {
gateway = storage.getGateway(gatewayId);
gateways.put(gatewayId, gateway);
}
IGatewayLink link = gatewayLinks.get(gatewayId);
if (link == null) {
link = gatewayLinkFactory.create(gateway);
gatewayLinks.put(gatewayId, link);
}
ApiEndpoint se = link.getApiEndpoint(api.getApiOrgId(), api.getApiId(), api.getApiVersion());
String apiEndpoint = se.getEndpoint();
api.setHttpEndpoint(apiEndpoint);
}
return apiRegistry;
} catch (StorageException | GatewayAuthenticationException e) {
throw new SystemErrorException(e);
} finally {
for (IGatewayLink link : gatewayLinks.values()) {
link.close();
}
}
}
use of io.apiman.manager.api.beans.summary.ApiEntryBean in project apiman by apiman.
the class EsStorage method getApiRegistry.
/**
* @see io.apiman.manager.api.core.IStorageQuery#getApiRegistry(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public ApiRegistryBean getApiRegistry(String organizationId, String clientId, String version) throws StorageException {
@SuppressWarnings("nls") BoolQueryBuilder query = QueryBuilders.boolQuery();
List<QueryBuilder> filter = query.filter();
filter.add(QueryBuilders.termQuery("clientOrganizationId", organizationId));
filter.add(QueryBuilders.termQuery("clientId", clientId));
filter.add(QueryBuilders.termQuery("clientVersion", version));
@SuppressWarnings("nls") SearchSourceBuilder builder = new SearchSourceBuilder().query(query).sort(new FieldSortBuilder("id").order(SortOrder.ASC)).size(500);
List<SearchHit> hits = listEntities(INDEX_MANAGER_POSTFIX_CONTRACT, builder);
ApiRegistryBean registry = new ApiRegistryBean();
for (SearchHit hit : hits) {
ApiEntryBean bean = EsMarshalling.unmarshallApiEntry(hit.getSourceAsMap());
ApiVersionBean svb = getApiVersion(bean.getApiOrgId(), bean.getApiId(), bean.getApiVersion());
Set<ApiGatewayBean> gateways = svb.getGateways();
if (gateways != null && !gateways.isEmpty()) {
ApiGatewayBean sgb = gateways.iterator().next();
bean.setGatewayId(sgb.getGatewayId());
}
registry.getApis().add(bean);
}
return registry;
}
use of io.apiman.manager.api.beans.summary.ApiEntryBean in project apiman by apiman.
the class EsMarshalling method unmarshallApiEntry.
/**
* Unmarshals the given map source into a bean.
* @param source the source
* @return the api entry
*/
public static ApiEntryBean unmarshallApiEntry(Map<String, Object> source) {
if (source == null) {
return null;
}
ApiEntryBean bean = new ApiEntryBean();
bean.setApiOrgId(asString(source.get("apiOrganizationId")));
bean.setApiOrgName(asString(source.get("apiOrganizationName")));
bean.setApiId(asString(source.get("apiId")));
bean.setApiName(asString(source.get("apiName")));
bean.setApiVersion(asString(source.get("apiVersion")));
bean.setPlanName(asString(source.get("planName")));
bean.setPlanId(asString(source.get("planId")));
bean.setPlanVersion(asString(source.get("planVersion")));
postMarshall(bean);
return bean;
}
Aggregations