use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsSubscriptionIdGet.
@Test
public void testSubscriptionsSubscriptionIdGet() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String subsID1 = UUID.randomUUID().toString();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = TestUtil.getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Subscription subscription = SampleTestObjectCreator.createSubscription(subsID1);
Mockito.when(apiStore.getSubscriptionByUUID(subsID1)).thenReturn(subscription);
Response response = subscriptionsApiService.subscriptionsSubscriptionIdGet(subsID1, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class APISubscriptionDAOImpl method getAPISubscriptionsByAPI.
/**
* Retrieve the list of subscriptions of an API
*
* @param apiId The UUID of API
* @return A list of {@link Subscription} objects
* @throws APIMgtDAOException If failed to get subscriptions.
*/
@Override
public List<Subscription> getAPISubscriptionsByAPI(String apiId) throws APIMgtDAOException {
final String getSubscriptionsByAPISql = "SELECT SUBS.UUID AS SUBS_UUID, SUBS.TIER_ID AS SUBS_TIER, " + "SUBS.API_ID AS API_ID, SUBS.APPLICATION_ID AS APP_ID, SUBS.SUB_STATUS AS SUB_STATUS, " + "SUBS.SUB_TYPE AS SUB_TYPE, APP.NAME AS APP_NAME, APP.APPLICATION_POLICY_ID AS APP_POLICY_ID, " + "APP.APPLICATION_STATUS AS APP_STATUS, " + "APP.CREATED_BY AS APP_OWNER, POLICY.NAME AS SUBS_POLICY " + "FROM AM_SUBSCRIPTION SUBS, AM_APPLICATION APP, AM_SUBSCRIPTION_POLICY POLICY " + "WHERE SUBS.API_ID = ? AND SUBS.APPLICATION_ID = APP.UUID AND SUBS.TIER_ID = POLICY.UUID " + "AND SUBS.SUB_STATUS NOT IN (?,?)";
try (Connection conn = DAOUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(getSubscriptionsByAPISql)) {
ps.setString(1, apiId);
ps.setString(2, SubscriptionStatus.ON_HOLD.name());
ps.setString(3, SubscriptionStatus.REJECTED.name());
try (ResultSet rs = ps.executeQuery()) {
return createSubscriptionsWithAppInformationOnly(rs);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting api subscriptions by api(apiId: " + apiId + ")", e);
}
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class ApiDAOImpl method deleteCompositeApi.
@Override
public void deleteCompositeApi(String apiId) throws APIMgtDAOException {
APISubscriptionDAO apiSubscriptionDAO = DAOFactory.getAPISubscriptionDAO();
List<Subscription> subscriptions = apiSubscriptionDAO.getAPISubscriptionsByAPI(apiId);
for (Subscription subscription : subscriptions) {
apiSubscriptionDAO.deleteAPISubscription(subscription.getId());
}
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(API_DELETE)) {
persistAPIDelete(connection, statement, apiId);
} catch (SQLException | IOException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "deleting Composite API: " + apiId, e);
}
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class ApiDAOImpl method getCompositeAPIApplicationId.
private String getCompositeAPIApplicationId(Connection connection, String apiId) throws APIMgtDAOException {
APISubscriptionDAO apiSubscriptionDAO = DAOFactory.getAPISubscriptionDAO();
List<Subscription> subscriptions = apiSubscriptionDAO.getAPISubscriptionsByAPI(apiId);
if (!subscriptions.isEmpty()) {
return subscriptions.get(0).getApplication().getId();
}
throw new IllegalStateException("Composite API ID " + apiId + " has no associated Application subscription");
}
use of org.wso2.eventing.Subscription in project carbon-apimgt by wso2.
the class APISubscriptionDAOImpl method getPendingAPISubscriptionsByApplication.
/**
* Retrieve the list of subscriptions of an Application which are in pending state
*
* @param applicationId The UUID of Application
* @return A list of {@link Subscription} objects which has pending status
* @throws APIMgtDAOException If failed to get subscriptions.
*/
@Override
public List<Subscription> getPendingAPISubscriptionsByApplication(String applicationId) throws APIMgtDAOException {
final String getSubscriptionsByAppSql = "SELECT SUBS.UUID AS SUBS_UUID, SUBS.TIER_ID AS SUBS_TIER, " + "SUBS.API_ID AS API_ID, SUBS.APPLICATION_ID AS APP_ID, SUBS.SUB_STATUS AS SUB_STATUS, " + "SUBS.SUB_TYPE AS SUB_TYPE, API.PROVIDER AS API_PROVIDER, API.NAME AS API_NAME, " + "API.CONTEXT AS API_CONTEXT, API.VERSION AS API_VERSION, POLICY.NAME AS SUBS_POLICY " + "FROM AM_SUBSCRIPTION SUBS, AM_API API, AM_SUBSCRIPTION_POLICY POLICY " + "WHERE SUBS.APPLICATION_ID = ? AND SUBS.API_ID = API.UUID AND SUBS.TIER_ID = POLICY.UUID " + "AND SUBS.SUB_STATUS=?";
try (Connection conn = DAOUtil.getConnection();
PreparedStatement ps = conn.prepareStatement(getSubscriptionsByAppSql)) {
ps.setString(1, applicationId);
ps.setString(2, SubscriptionStatus.ON_HOLD.toString());
try (ResultSet rs = ps.executeQuery()) {
return createSubscriptionsWithApiInformationOnly(rs);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting pending api subscriptions by application(appId: " + applicationId + ")", e);
}
}
Aggregations