Search in sources :

Example 1 with SubscriptionList

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

Example 2 with 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;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Application(org.wso2.carbon.apimgt.core.models.Application)

Example 3 with 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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.SubscriptionListDTO)

Example 4 with SubscriptionList

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());
}
Also used : ArrayList(java.util.ArrayList) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionListDTO) Test(org.testng.annotations.Test)

Example 5 with SubscriptionList

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());
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) ArrayList(java.util.ArrayList) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)10 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)10 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)4 SQLException (java.sql.SQLException)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)2 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)2 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 API (org.wso2.carbon.apimgt.core.models.API)2 Application (org.wso2.carbon.apimgt.core.models.Application)2 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)2 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)2 SubscriptionListDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.SubscriptionListDTO)2 Request (org.wso2.msf4j.Request)2 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1