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");
}
}
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;
}
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());
}
}
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;
}
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);
}
}
Aggregations