Search in sources :

Example 1 with SubscriptionValidationData

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");
    }
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.core.models.events.SubscriptionEvent)

Example 2 with SubscriptionValidationData

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;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) APIMgtConstants(org.wso2.carbon.apimgt.core.util.APIMgtConstants)

Example 3 with SubscriptionValidationData

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;
}
Also used : ArrayList(java.util.ArrayList) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData)

Example 4 with SubscriptionValidationData

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);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) API(org.wso2.carbon.apimgt.core.models.API) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) Subscription(org.wso2.carbon.apimgt.core.models.Subscription)

Example 5 with SubscriptionValidationData

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.");
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) API(org.wso2.carbon.apimgt.core.models.API) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Aggregations

SubscriptionValidationData (org.wso2.carbon.apimgt.core.models.SubscriptionValidationData)16 Test (org.testng.annotations.Test)6 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)6 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)5 API (org.wso2.carbon.apimgt.core.models.API)5 Application (org.wso2.carbon.apimgt.core.models.Application)5 ArrayList (java.util.ArrayList)4 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)4 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)4 SQLException (java.sql.SQLException)3 SubscriptionEvent (org.wso2.carbon.apimgt.core.models.events.SubscriptionEvent)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)2 OAuthApplicationInfo (org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo)2 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionDTO)2 HashMap (java.util.HashMap)1 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)1 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)1