use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.
the class GatewayUtils method retrieveDeployedLocalEntries.
public static List<String> retrieveDeployedLocalEntries(String apiName, String version, String tenantDomain) throws APIManagementException {
try {
SubscriptionDataStore tenantSubscriptionStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
List<String> deployedLocalEntries = new ArrayList<>();
if (tenantSubscriptionStore != null) {
API retrievedAPI = tenantSubscriptionStore.getApiByNameAndVersion(apiName, version);
if (retrievedAPI != null) {
MessageContext.setCurrentMessageContext(createAxis2MessageContext());
LocalEntryServiceProxy localEntryServiceProxy = new LocalEntryServiceProxy(tenantDomain);
String localEntryKey = retrievedAPI.getUuid();
if (APIConstants.GRAPHQL_API.equals(retrievedAPI.getApiType())) {
localEntryKey = retrievedAPI.getUuid().concat(APIConstants.GRAPHQL_LOCAL_ENTRY_EXTENSION);
}
if (localEntryServiceProxy.isEntryExists(localEntryKey)) {
OMElement entry = localEntryServiceProxy.getEntry(localEntryKey);
deployedLocalEntries.add(entry.toString());
}
}
}
return deployedLocalEntries;
} catch (AxisFault axisFault) {
throw new APIManagementException("Error while retrieving LocalEntries", axisFault, ExceptionCodes.INTERNAL_ERROR);
} finally {
MessageContext.destroyCurrentMessageContext();
}
}
use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.
the class UtilsTest method getSelectedAPI3.
@Test
public void getSelectedAPI3() {
SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
Mockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
Mockito.when(subscriptionDataHolder.getTenantSubscriptionStore("carbon.super")).thenReturn(subscriptionDataStore);
Mockito.when(subscriptionDataStore.getAllAPIsByContextList()).thenReturn(apiMap());
Map<String, API> selectedAPIList = Utils.getSelectedAPIList("/api1/1.0.0/cde?c=y", "carbon.super");
Assert.assertEquals(selectedAPIList.size(), 2);
Assert.assertEquals(selectedAPIList.keySet().iterator().next(), "/api1/1.0.0");
}
use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.
the class UtilsTest method getSelectedAPI4.
@Test
public void getSelectedAPI4() {
SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
Mockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
Mockito.when(subscriptionDataHolder.getTenantSubscriptionStore("carbon.super")).thenReturn(subscriptionDataStore);
Mockito.when(subscriptionDataStore.getAllAPIsByContextList()).thenReturn(apiMap());
Map<String, API> selectedAPIList = Utils.getSelectedAPIList("/api1/abc/1.0.0/cde?c=y", "carbon.super");
Assert.assertEquals(selectedAPIList.size(), 3);
Assert.assertEquals(selectedAPIList.keySet().iterator().next(), "/api1/abc/1.0.0");
}
use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.
the class UtilsTest method getSelectedAPI2.
@Test
public void getSelectedAPI2() {
SubscriptionDataHolder subscriptionDataHolder = Mockito.mock(SubscriptionDataHolder.class);
Mockito.when(SubscriptionDataHolder.getInstance()).thenReturn(subscriptionDataHolder);
SubscriptionDataStore subscriptionDataStore = Mockito.mock(SubscriptionDataStore.class);
Mockito.when(subscriptionDataHolder.getTenantSubscriptionStore("carbon.super")).thenReturn(subscriptionDataStore);
Mockito.when(subscriptionDataStore.getAllAPIsByContextList()).thenReturn(apiMap());
Map<String, API> selectedAPIList = Utils.getSelectedAPIList("/api1/abc/cde?c=y", "carbon.super");
Assert.assertEquals(selectedAPIList.size(), 2);
Assert.assertEquals(selectedAPIList.keySet().iterator().next(), "/api1/abc");
}
use of org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisGet.
public Response apisGet(String context, String version, String tenantDomain, MessageContext messageContext) {
tenantDomain = GatewayUtils.validateTenantDomain(tenantDomain, messageContext);
SubscriptionDataStore subscriptionDataStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
if (subscriptionDataStore == null) {
log.warn("Subscription data store is not initialized for " + tenantDomain);
return Response.status(Response.Status.NOT_FOUND).build();
}
if (StringUtils.isNotEmpty(context) && StringUtils.isNotEmpty(version)) {
API api = subscriptionDataStore.getApiByContextAndVersion(context, version);
if (api == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
APIListDTO apiListDTO = GatewayUtils.generateAPIListDTO(Collections.singletonList(api));
return Response.ok().entity(apiListDTO).build();
} else if ((StringUtils.isEmpty(context) && StringUtils.isNotEmpty(version)) || (StringUtils.isNotEmpty(context) && StringUtils.isEmpty(version))) {
return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorDTO().moreInfo("required parameters " + "are missing")).build();
} else {
List<API> apiList = subscriptionDataStore.getAPIs();
APIListDTO apiListDTO = GatewayUtils.generateAPIListDTO(apiList);
return Response.status(Response.Status.OK).entity(apiListDTO).build();
}
}
Aggregations