use of org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionList in project carbon-apimgt by wso2.
the class APISubscriptionDAOImpl method createSubscriptionsFromResultSet.
private List<Subscription> createSubscriptionsFromResultSet(ResultSet rs) throws APIMgtDAOException {
List<Subscription> subscriptionList = new ArrayList<>();
Subscription subscription;
if (rs == null) {
return new ArrayList<>();
}
while ((subscription = createSubscriptionWithApiAndAppInformation(rs)) != null) {
subscriptionList.add(subscription);
}
return subscriptionList;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionList in project carbon-apimgt by wso2.
the class APISubscriptionDAOImpl method createSubscriptionsWithAppInformationOnly.
private List<Subscription> createSubscriptionsWithAppInformationOnly(ResultSet rs) throws APIMgtDAOException {
List<Subscription> subscriptionList = new ArrayList<>();
try {
Subscription subscription;
while (rs.next()) {
String subscriptionId = rs.getString("SUBS_UUID");
String subscriptionTier = rs.getString("SUBS_POLICY");
Application app = new Application(rs.getString("APP_NAME"), rs.getString("APP_OWNER"));
app.setId(rs.getString("APP_ID"));
app.setStatus(rs.getString("APP_STATUS"));
subscription = new Subscription(subscriptionId, app, null, new SubscriptionPolicy(subscriptionTier));
subscription.setStatus(APIMgtConstants.SubscriptionStatus.valueOf(rs.getString("SUB_STATUS")));
subscriptionList.add(subscription);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "creating subscriptions app information", e);
}
return subscriptionList;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionList in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method subscriptionsGet.
/**
* Retrieve all subscriptions for a particular API
*
* @param apiId ID of the API
* @param limit Maximum subscriptions to return
* @param offset Starting position of the pagination
* @param ifNoneMatch If-Match header value
* @param request ms4j request object
* @return List of qualifying subscriptions DTOs as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response subscriptionsGet(String apiId, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
List<Subscription> subscriptionList;
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
if (StringUtils.isNotEmpty(apiId)) {
subscriptionList = apiPublisher.getSubscriptionsByAPI(apiId);
SubscriptionListDTO subscriptionListDTO = MappingUtil.fromSubscriptionListToDTO(subscriptionList, limit, offset);
return Response.ok().entity(subscriptionListDTO).build();
} else {
RestApiUtil.handleBadRequest("API ID can not be null", log);
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving subscriptions of API " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return null;
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionList in project carbon-apimgt by wso2.
the class SubscriptionMappingUtilTestCase method testFromSubscriptionListToDTO.
@Test
public void testFromSubscriptionListToDTO() {
String subUuid1 = UUID.randomUUID().toString();
String subUuid2 = UUID.randomUUID().toString();
Subscription subscription1 = SampleTestObjectCreator.createSubscription(subUuid1);
Subscription subscription2 = SampleTestObjectCreator.createSubscription(subUuid2);
List<Subscription> subscriptionList = new ArrayList<>();
subscriptionList.add(subscription1);
subscriptionList.add(subscription2);
SubscriptionListDTO subscriptionListDTO = SubscriptionMappingUtil.fromSubscriptionListToDTO(subscriptionList, 10, 0);
assertEquals(subscriptionListDTO.getCount(), (Integer) subscriptionList.size());
assertEquals(subscription1.getId(), subscriptionListDTO.getList().get(0).getSubscriptionId());
assertEquals(subscription1.getApi().getName(), subscriptionListDTO.getList().get(0).getApiName());
assertEquals(subscription1.getApi().getId(), subscriptionListDTO.getList().get(0).getApiIdentifier());
assertEquals(subscription1.getApi().getVersion(), subscriptionListDTO.getList().get(0).getApiVersion());
assertEquals(SubscriptionDTO.LifeCycleStatusEnum.valueOf(subscription1.getStatus().toString()).name(), subscriptionListDTO.getList().get(0).getLifeCycleStatus().name());
assertEquals(subscriptionListDTO.getCount(), (Integer) subscriptionList.size());
assertEquals(subscription2.getId(), subscriptionListDTO.getList().get(1).getSubscriptionId());
assertEquals(subscription2.getApi().getName(), subscriptionListDTO.getList().get(1).getApiName());
assertEquals(subscription2.getApi().getId(), subscriptionListDTO.getList().get(1).getApiIdentifier());
assertEquals(subscription2.getApi().getVersion(), subscriptionListDTO.getList().get(1).getApiVersion());
assertEquals(SubscriptionDTO.LifeCycleStatusEnum.valueOf(subscription2.getStatus().toString()).name(), subscriptionListDTO.getList().get(1).getLifeCycleStatus().name());
}
use of org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionList in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsGetfromAPI.
@Test
public void testSubscriptionsGetfromAPI() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String apiId = UUID.randomUUID().toString();
String subsID1 = UUID.randomUUID().toString();
String subsID2 = 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);
List<Subscription> subscriptionList = new ArrayList<>();
subscriptionList.add(SampleTestObjectCreator.createSubscription(subsID1));
subscriptionList.add(SampleTestObjectCreator.createSubscription(subsID2));
Mockito.when(apiStore.getSubscriptionsByAPI(apiId)).thenReturn(subscriptionList);
Response response = subscriptionsApiService.subscriptionsGet(apiId, null, null, 0, 10, null, request);
Assert.assertEquals(200, response.getStatus());
}
Aggregations