use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method addAPISubscription.
@Override
public void addAPISubscription(List<SubscriptionValidationData> subscriptionValidationDataList) throws GatewayException {
SubscriptionEvent subscriptionAddEvent = new SubscriptionEvent(APIMgtConstants.GatewayEventTypes.SUBSCRIPTION_CREATE);
subscriptionAddEvent.setSubscriptionsList(subscriptionValidationDataList);
publishToStoreTopic(subscriptionAddEvent);
if (log.isDebugEnabled()) {
log.debug("Subscription created event has been successfully published to broker");
}
}
use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.
the class SubscriptionCreationWorkflow method completeWorkflow.
public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
if (subscription == null) {
// this is when complete method is executed through workflow rest api
subscription = apiSubscriptionDAO.getAPISubscription(getWorkflowReference());
}
WorkflowResponse response = workflowExecutor.complete(this);
setStatus(response.getWorkflowStatus());
APIMgtConstants.SubscriptionStatus subscriptionState = null;
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Subscription Creation workflow complete: Approved");
}
subscriptionState = APIMgtConstants.SubscriptionStatus.ACTIVE;
} else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Subscription Creation workflow complete: Rejected");
}
subscriptionState = APIMgtConstants.SubscriptionStatus.REJECTED;
}
// Add subscription to gateway
apiSubscriptionDAO.updateSubscriptionStatus(getWorkflowReference(), subscriptionState);
updateWorkflowEntries(this);
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (subscription.getApi() != null && subscription.getApplication() != null) {
List<SubscriptionValidationData> subscriptionValidationDataList = apiSubscriptionDAO.getAPISubscriptionsOfAPIForValidation(subscription.getApi().getContext(), subscription.getApi().getVersion(), subscription.getApplication().getId());
if (subscriptionValidationDataList != null && !subscriptionValidationDataList.isEmpty()) {
apiGateway.addAPISubscription(subscriptionValidationDataList);
if (log.isDebugEnabled()) {
log.debug("Subscription created for API : " + subscription.getApi().getName() + " with " + "application : " + subscription.getApplication().getName() + " has been successfully " + "published to gateway");
}
}
}
}
return response;
}
use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method createSubscriptionValidationDataList.
private List<SubscriptionValidationData> createSubscriptionValidationDataList() throws Exception {
SubscriptionValidationData subscriptionValidationDataOne = SampleTestObjectCreator.createSubscriptionValidationData();
SubscriptionValidationData subscriptionValidationDataTwo = SampleTestObjectCreator.createSubscriptionValidationData();
List<SubscriptionValidationData> subscriptionValidationDataList = new ArrayList<>();
subscriptionValidationDataList.add(subscriptionValidationDataOne);
subscriptionValidationDataList.add(subscriptionValidationDataTwo);
return subscriptionValidationDataList;
}
use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.
the class APIPublisherImpl method updateSubscriptionStatus.
/**
* Update the subscription status
*
* @param subId Subscription ID
* @param subStatus Subscription Status
* @throws APIManagementException If failed to update subscription status
*/
@Override
public void updateSubscriptionStatus(String subId, APIMgtConstants.SubscriptionStatus subStatus) throws APIManagementException {
try {
getApiSubscriptionDAO().updateSubscriptionStatus(subId, subStatus);
Subscription subscription = getApiSubscriptionDAO().getAPISubscription(subId);
if (subscription != null) {
API subscribedApi = subscription.getApi();
List<SubscriptionValidationData> subscriptionValidationDataList = getApiSubscriptionDAO().getAPISubscriptionsOfAPIForValidation(subscribedApi.getContext(), subscribedApi.getVersion(), subscription.getApplication().getId());
getApiGateway().updateAPISubscriptionStatus(subscriptionValidationDataList);
}
} catch (APIMgtDAOException e) {
throw new APIManagementException(e);
}
}
use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.
the class SubscriptionDAOImplIT method testGetSubscriptionForApplicationAndKeyType.
@Test
public void testGetSubscriptionForApplicationAndKeyType() throws Exception {
// add test apis, apps and subscriptions
// app1: api2
// app2: api1, api2, api3
// app3: api3
// app4: api1, api2, api3, api4
ApisAndApps apisAndApps = createApisAppsAndSubscriptions();
APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
API api2 = apisAndApps.getApis().get(1);
Application app1 = apisAndApps.getApps().get(0);
registerOAuthAppForApplication(applicationDAO, "client-key-for-app-1", app1.getId());
// get subscriptions of app1-PRODUCTION
List<SubscriptionValidationData> subscriptionValidationDataProd = subscriptionDAO.getAPISubscriptionsOfAppForValidation(app1.getId(), "PRODUCTION");
// validate subscriptions
Assert.assertEquals(subscriptionValidationDataProd.size(), 1, "There should be 1 subscriptions (only).");
SubscriptionValidationData validationData = subscriptionValidationDataProd.get(0);
Assert.assertNotNull(validationData);
Assert.assertEquals(validationData.getApiName(), api2.getName());
Assert.assertEquals(validationData.getApiVersion(), api2.getVersion());
Assert.assertEquals(validationData.getApplicationId(), app1.getId());
Assert.assertEquals(validationData.getKeyEnvType(), "PRODUCTION");
// list subscriptions for app1-SANDBOX
List<SubscriptionValidationData> subscriptionValidationDataSandbox = subscriptionDAO.getAPISubscriptionsOfAppForValidation(app1.getId(), "SANDBOX");
Assert.assertEquals(subscriptionValidationDataSandbox.size(), 0, "There shouldn't be any subscriptions.");
}
Aggregations