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