Search in sources :

Example 6 with SubscriptionDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.SubscriptionDTO in project carbon-apimgt by wso2.

the class SubscriptionMappingUtil method fromSubscriptionToDTO.

/**
 * Converts a SubscribedAPI object into SubscriptionDTO
 *
 * @param subscription SubscribedAPI object
 * @return SubscriptionDTO corresponds to SubscribedAPI object
 */
public static SubscriptionDTO fromSubscriptionToDTO(Subscription subscription) {
    SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
    subscriptionDTO.setSubscriptionId(subscription.getId());
    if (subscription.getApi() != null) {
        subscriptionDTO.setApiIdentifier(subscription.getApi().getId());
        subscriptionDTO.setApiName(subscription.getApi().getName());
        subscriptionDTO.setApiVersion(subscription.getApi().getVersion());
    }
    if (subscription.getApplication() != null) {
        subscriptionDTO.setApplicationId(subscription.getApplication().getId());
    }
    subscriptionDTO.setPolicy(subscription.getPolicy().getPolicyName());
    subscriptionDTO.setLifeCycleStatus(SubscriptionDTO.LifeCycleStatusEnum.valueOf(subscription.getStatus().toString()));
    return subscriptionDTO;
}
Also used : SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO)

Example 7 with SubscriptionDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.SubscriptionDTO in project carbon-apimgt by wso2.

the class SubscriptionsApiServiceImplTestCase method testSubscriptionsPost.

@Test
public void testSubscriptionsPost() throws APIManagementException, NotFoundException {
    TestUtil.printTestMethodName();
    String applicationId = UUID.randomUUID().toString();
    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);
    Application application = SampleTestObjectCreator.createDefaultApplication();
    Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
    Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
    API api = TestUtil.createApi("provider1", apiId, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", TestUtil.createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
    Mockito.when(apiStore.getApplicationByUuid(applicationId)).thenReturn(application);
    Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
    SubscriptionDTO subscriptionDTO = SubscriptionMappingUtil.fromSubscriptionToDTO(SampleTestObjectCreator.createSubscription(subsID1));
    Response response = subscriptionsApiService.subscriptionsPost(subscriptionDTO, request);
    Assert.assertEquals(404, 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) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Request(org.wso2.msf4j.Request) API(org.wso2.carbon.apimgt.core.models.API) Application(org.wso2.carbon.apimgt.core.models.Application) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with SubscriptionDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.SubscriptionDTO in project carbon-apimgt by wso2.

the class MappingUtil method convertToSubscriptionListDto.

/**
 * This method converts List of SubscriptionValidationData into SubscriptionDTO list.
 *
 * @param subscriptionValidationData List of Subscription Validation Data
 * @return SubscriptionDTO list
 */
public static List<SubscriptionDTO> convertToSubscriptionListDto(List<SubscriptionValidationData> subscriptionValidationData) {
    List<SubscriptionDTO> subscriptionDTOList = new ArrayList<>();
    for (SubscriptionValidationData subscriptionData : subscriptionValidationData) {
        SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
        subscriptionDTO.setApiName(subscriptionData.getApiName());
        subscriptionDTO.setApiContext(subscriptionData.getApiContext());
        subscriptionDTO.setApiVersion(subscriptionData.getApiVersion());
        subscriptionDTO.setApiProvider(subscriptionData.getApiProvider());
        subscriptionDTO.setConsumerKey(subscriptionData.getConsumerKey());
        subscriptionDTO.setSubscriptionPolicy(subscriptionData.getSubscriptionPolicy());
        subscriptionDTO.setKeyEnvType(subscriptionData.getKeyEnvType());
        subscriptionDTO.setApplicationId(subscriptionData.getApplicationId());
        subscriptionDTO.setStatus(subscriptionData.getStatus());
        subscriptionDTOList.add(subscriptionDTO);
    }
    return subscriptionDTOList;
}
Also used : ArrayList(java.util.ArrayList) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionDTO)

Example 9 with SubscriptionDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.SubscriptionDTO in project carbon-apimgt by wso2.

the class SubscriptionMappingUtil method fromSubscriptionListToDTO.

/**
 * Converts a List object of SubscribedAPIs into a DTO
 *
 * @param subscriptions a list of SubscribedAPI objects
 * @param query         query to filter subscriptions
 * @return SubscriptionListDTO object containing SubscriptionDTOs
 */
public static SubscriptionListDTO fromSubscriptionListToDTO(List<SubscribedAPI> subscriptions, String query) throws APIManagementException {
    SubscriptionListDTO subscriptionListDTO = new SubscriptionListDTO();
    List<SubscriptionDTO> subscriptionDTOs = subscriptionListDTO.getList();
    if (subscriptionDTOs == null) {
        subscriptionDTOs = new ArrayList<>();
        subscriptionListDTO.setList(subscriptionDTOs);
    }
    query = query.toLowerCase().trim();
    for (SubscribedAPI sub : subscriptions) {
        SubscriptionDTO subscription = fromSubscriptionToDTO(sub);
        if (subscription.getApplicationInfo().getName().toLowerCase().contains(query) || subscription.getApplicationInfo().getSubscriber().toLowerCase().contains(query) || subscription.getThrottlingPolicy().toLowerCase().contains(query)) {
            subscriptionDTOs.add(subscription);
        }
    }
    subscriptionListDTO.setCount(subscriptionDTOs.size());
    return subscriptionListDTO;
}
Also used : SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO) SubscriptionListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionListDTO)

Example 10 with SubscriptionDTO

use of org.wso2.carbon.apimgt.rest.api.gateway.dto.SubscriptionDTO in project carbon-apimgt by wso2.

the class SubscriptionMappingUtil method fromSubscriptionToDTO.

/**
 * Converts a SubscribedAPI object into SubscriptionDTO
 *
 * @param subscription SubscribedAPI object
 * @return SubscriptionDTO corresponds to SubscribedAPI object
 */
public static SubscriptionDTO fromSubscriptionToDTO(SubscribedAPI subscription) throws APIManagementException {
    SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
    subscriptionDTO.setSubscriptionId(subscription.getUUID());
    subscriptionDTO.setApplicationInfo(fromApplicationToApplicationInfoDTO(subscription.getApplication()));
    subscriptionDTO.setSubscriptionStatus(SubscriptionDTO.SubscriptionStatusEnum.valueOf(subscription.getSubStatus()));
    subscriptionDTO.setThrottlingPolicy(subscription.getTier().getName());
    return subscriptionDTO;
}
Also used : SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO)

Aggregations

SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)8 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)7 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)7 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.SubscriptionDTO)7 Application (org.wso2.carbon.apimgt.api.model.Application)6 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO)6 HashMap (java.util.HashMap)5 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)5 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)5 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.SubscriptionDTO)5 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO)5 ArrayList (java.util.ArrayList)4 ApiTypeWrapper (org.wso2.carbon.apimgt.api.model.ApiTypeWrapper)4 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 APIMgtAuthorizationFailedException (org.wso2.carbon.apimgt.api.APIMgtAuthorizationFailedException)3 SubscriptionAlreadyExistingException (org.wso2.carbon.apimgt.api.SubscriptionAlreadyExistingException)3 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)3