use of org.wso2.carbon.apimgt.rest.api.publisher.v1.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 limit max number of objects returned
* @param offset starting index
* @param organization identifier of the organization
* @return SubscriptionListDTO object containing SubscriptionDTOs
*/
public static SubscriptionListDTO fromSubscriptionListToDTO(List<SubscribedAPI> subscriptions, Integer limit, Integer offset, String organization) throws APIManagementException {
SubscriptionListDTO subscriptionListDTO = new SubscriptionListDTO();
List<SubscriptionDTO> subscriptionDTOs = subscriptionListDTO.getList();
if (subscriptionDTOs == null) {
subscriptionDTOs = new ArrayList<>();
subscriptionListDTO.setList(subscriptionDTOs);
}
// identifying the proper start and end indexes
int size = subscriptions.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
for (int i = start; i <= end; i++) {
try {
SubscribedAPI subscription = subscriptions.get(i);
subscriptionDTOs.add(fromSubscriptionToDTO(subscription, organization));
} catch (APIManagementException e) {
log.error("Error while obtaining api metadata", e);
}
}
subscriptionListDTO.setCount(subscriptionDTOs.size());
return subscriptionListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromSubscriptionToDTO.
public static SubscriptionDTO fromSubscriptionToDTO(SubscribedAPI subscription, ApiTypeWrapper apiTypeWrapper, String organization) throws APIManagementException {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setSubscriptionId(subscription.getUUID());
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
Set<String> deniedTiers = apiConsumer.getDeniedTiers(organization);
Map<String, Tier> tierMap = APIUtil.getTiers(organization);
if (apiTypeWrapper != null && !apiTypeWrapper.isAPIProduct()) {
API api = apiTypeWrapper.getApi();
subscriptionDTO.setApiId(api.getUUID());
APIInfoDTO apiInfo = APIMappingUtil.fromAPIToInfoDTO(api);
APIMappingUtil.setThrottlePoliciesAndMonetization(api, apiInfo, deniedTiers, tierMap);
subscriptionDTO.setApiInfo(apiInfo);
} else {
APIProduct apiProduct = apiTypeWrapper.getApiProduct();
subscriptionDTO.setApiId(apiProduct.getUuid());
APIInfoDTO apiInfo = APIMappingUtil.fromAPIToInfoDTO(apiProduct, organization);
APIMappingUtil.setThrottlePoliciesAndMonetization(apiProduct, apiInfo, deniedTiers, tierMap);
subscriptionDTO.setApiInfo(apiInfo);
}
Application application = subscription.getApplication();
subscriptionDTO.setApplicationId(subscription.getApplication().getUUID());
subscriptionDTO.setStatus(SubscriptionDTO.StatusEnum.valueOf(subscription.getSubStatus()));
subscriptionDTO.setThrottlingPolicy(subscription.getTier().getName());
subscriptionDTO.setRequestedThrottlingPolicy(subscription.getRequestedTier().getName());
ApplicationInfoDTO applicationInfoDTO = ApplicationMappingUtil.fromApplicationToInfoDTO(application);
subscriptionDTO.setApplicationInfo(applicationInfoDTO);
return subscriptionDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.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 limit max number of objects returned
* @param offset starting index
* @return SubscriptionListDTO object containing SubscriptionDTOs
*/
public static SubscriptionListDTO fromSubscriptionListToDTO(List<SubscribedAPI> subscriptions, Integer limit, Integer offset) throws APIManagementException {
SubscriptionListDTO subscriptionListDTO = new SubscriptionListDTO();
List<SubscriptionDTO> subscriptionDTOs = subscriptionListDTO.getList();
if (subscriptionDTOs == null) {
subscriptionDTOs = new ArrayList<>();
subscriptionListDTO.setList(subscriptionDTOs);
}
// identifying the proper start and end indexes
int size = subscriptions.size();
int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
for (int i = start; i <= end; i++) {
SubscribedAPI subscription = subscriptions.get(i);
subscriptionDTOs.add(fromSubscriptionToDTO(subscription));
}
subscriptionListDTO.setCount(subscriptionDTOs.size());
return subscriptionListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method blockSubscription.
/**
* Blocks a subscription
*
* @param subscriptionId Subscription identifier
* @param blockState block state; either BLOCKED or PROD_ONLY_BLOCKED
* @param ifMatch If-Match header value
* @return 200 response and the updated subscription if subscription block is successful
*/
public Response blockSubscription(String subscriptionId, String blockState, String ifMatch, MessageContext messageContext) {
String username = RestApiCommonUtil.getLoggedInUsername();
try {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
APIProvider apiProvider = RestApiCommonUtil.getProvider(username);
// validates the subscriptionId if it exists
SubscribedAPI currentSubscription = apiProvider.getSubscriptionByUUID(subscriptionId);
if (currentSubscription == null) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_SUBSCRIPTION, subscriptionId, log);
}
SubscribedAPI subscribedAPI = new SubscribedAPI(subscriptionId);
subscribedAPI.setSubStatus(blockState);
apiProvider.updateSubscription(subscribedAPI);
SubscribedAPI updatedSubscription = apiProvider.getSubscriptionByUUID(subscriptionId);
SubscriptionDTO subscriptionDTO = SubscriptionMappingUtil.fromSubscriptionToDTO(updatedSubscription);
return Response.ok().entity(subscriptionDTO).build();
} catch (APIManagementException e) {
String msg = "Error while blocking the subscription " + subscriptionId;
RestApiUtil.handleInternalServerError(msg, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionValidationDataUtil method fromSubscriptionToSubscriptionListDTO.
public static SubscriptionListDTO fromSubscriptionToSubscriptionListDTO(List<Subscription> model) {
SubscriptionListDTO subscriptionListDTO = new SubscriptionListDTO();
if (model != null) {
for (Subscription subsModel : model) {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setSubscriptionUUID(subsModel.getSubscriptionUUID());
subscriptionDTO.setApplicationUUID(subsModel.getApplicationUUID());
subscriptionDTO.setApiUUID(subsModel.getApiUUID());
subscriptionDTO.setApiId(subsModel.getApiId());
subscriptionDTO.setAppId(subsModel.getAppId());
subscriptionDTO.setSubscriptionId(subsModel.getSubscriptionId());
subscriptionDTO.setPolicyId(subsModel.getPolicyId());
subscriptionDTO.setSubscriptionState(subsModel.getSubscriptionState());
subscriptionListDTO.getList().add(subscriptionDTO);
}
subscriptionListDTO.setCount(model.size());
} else {
subscriptionListDTO.setCount(0);
}
return subscriptionListDTO;
}
Aggregations