Search in sources :

Example 11 with SubscriptionValidationData

use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method deleteAPISubscription.

/**
 * {@inheritDoc}
 */
@Override
public void deleteAPISubscription(List<SubscriptionValidationData> subscriptionValidationDataList) throws GatewayException {
    SubscriptionEvent subscriptionDeleteEvent = new SubscriptionEvent(APIMgtConstants.GatewayEventTypes.SUBSCRIPTION_DELETE);
    subscriptionDeleteEvent.setSubscriptionsList(subscriptionValidationDataList);
    publishToStoreTopic(subscriptionDeleteEvent);
    if (log.isDebugEnabled()) {
        log.debug("Subscription deleted event has been successfully published to broker");
    }
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.core.models.events.SubscriptionEvent)

Example 12 with SubscriptionValidationData

use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.

the class SubscriptionDeletionWorkflow method completeWorkflow.

public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
    if (subscription == null) {
        // this is when complete method is executed through workflow rest api
        this.subscription = apiSubscriptionDAO.getAPISubscription(getWorkflowReference());
    }
    WorkflowResponse response = workflowExecutor.complete(this);
    setStatus(response.getWorkflowStatus());
    List<SubscriptionValidationData> subscriptionValidationDataList = null;
    if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Subscription deletion workflow complete: Approved");
        }
        if (subscription.getApi() != null && subscription.getApplication() != null) {
            subscriptionValidationDataList = apiSubscriptionDAO.getAPISubscriptionsOfAPIForValidation(subscription.getApi().getContext(), subscription.getApi().getVersion(), subscription.getApplication().getId());
        }
        apiSubscriptionDAO.deleteAPISubscription(getWorkflowReference());
    } else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
        if (log.isDebugEnabled()) {
            log.debug("Subscription deletion workflow complete: Rejected");
        }
    }
    updateWorkflowEntries(this);
    if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
        if (subscriptionValidationDataList != null && !subscriptionValidationDataList.isEmpty()) {
            apiGateway.deleteAPISubscription(subscriptionValidationDataList);
            if (log.isDebugEnabled()) {
                log.debug("Subscription for API : " + subscription.getApi().getName() + " with " + "application : " + subscription.getApplication().getName() + " has been successfully " + "removed from gateway");
            }
        }
    }
    return response;
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData)

Example 13 with SubscriptionValidationData

use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.

the class MappingUtilTestCase method convertToSubscriptionListDTOTest.

@Test
public void convertToSubscriptionListDTOTest() {
    List<SubscriptionValidationData> validationDataList = new ArrayList<>();
    validationDataList.add(SampleTestObjectCreator.createSubscriptionValidationData());
    validationDataList.add(SampleTestObjectCreator.createSubscriptionValidationData());
    validationDataList.add(SampleTestObjectCreator.createSubscriptionValidationData());
    validationDataList.add(SampleTestObjectCreator.createSubscriptionValidationData());
    List<SubscriptionDTO> subscriptionListDTO = MappingUtil.convertToSubscriptionListDto(validationDataList);
    Assert.assertNotNull(subscriptionListDTO);
    Assert.assertEquals(validationDataList.size(), subscriptionListDTO.size());
    for (int i = 0; i < subscriptionListDTO.size(); i++) {
        Assert.assertEquals(subscriptionListDTO.get(i).getApiName(), validationDataList.get(i).getApiName());
        Assert.assertEquals(subscriptionListDTO.get(i).getApiContext(), validationDataList.get(i).getApiContext());
        Assert.assertEquals(subscriptionListDTO.get(i).getApiProvider(), validationDataList.get(i).getApiProvider());
        Assert.assertEquals(subscriptionListDTO.get(i).getApiVersion(), validationDataList.get(i).getApiVersion());
    }
}
Also used : ArrayList(java.util.ArrayList) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionDTO) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Test(org.testng.annotations.Test)

Example 14 with SubscriptionValidationData

use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createSubscriptionValidationData.

/**
 * Create SubscriptionValidationData object.
 *
 * @return SubscriptionValidationData object
 */
public static SubscriptionValidationData createSubscriptionValidationData() {
    SubscriptionValidationData subscriptionData = new SubscriptionValidationData(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString());
    subscriptionData.setSubscriptionPolicy(UUID.randomUUID().toString());
    return subscriptionData;
}
Also used : SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData)

Example 15 with SubscriptionValidationData

use of org.wso2.carbon.apimgt.core.models.SubscriptionValidationData in project carbon-apimgt by wso2.

the class APISubscriptionDAOImpl method getAPISubscriptionsOfAppForValidation.

/**
 * Retrieve the list of subscriptions with a given application and key type for validation
 *
 * @param applicationId UUID of the application
 * @param keyType       Application key type
 * @return A list of {@link SubscriptionValidationData} objects
 * @throws APIMgtDAOException If failed to get subscriptions.
 */
public List<SubscriptionValidationData> getAPISubscriptionsOfAppForValidation(String applicationId, String keyType) throws APIMgtDAOException {
    final String getSubscriptionsByAPISql = "SELECT SUBS.API_ID AS API_ID, SUBS.APPLICATION_ID AS APP_ID,SUBS" + ".SUB_STATUS AS SUB_STATUS, API.PROVIDER AS API_PROVIDER, API.NAME AS API_NAME, API.CONTEXT AS " + "API_CONTEXT, API.VERSION AS API_VERSION, SUBS.TIER_ID AS SUBS_POLICY , KEY_MAP.CLIENT_ID AS " + "CLIENT_ID,KEY_MAP.KEY_TYPE AS KEY_ENV_TYPE FROM AM_SUBSCRIPTION SUBS, AM_API API,AM_APP_KEY_MAPPING " + "KEY_MAP WHERE SUBS.API_ID = API.UUID AND KEY_MAP.APPLICATION_ID = SUBS.APPLICATION_ID AND SUBS" + ".APPLICATION_ID = ? AND KEY_MAP.KEY_TYPE = ?";
    try (Connection conn = DAOUtil.getConnection();
        PreparedStatement ps = conn.prepareStatement(getSubscriptionsByAPISql)) {
        ps.setString(1, applicationId);
        ps.setString(2, keyType);
        try (ResultSet rs = ps.executeQuery()) {
            return createSubscriptionValidationDataFromResultSet(rs);
        }
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting application subscriptions for validation(appId: " + applicationId + ", keyType: " + keyType + ")", e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

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