use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ApplicationInfoDTO in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromApplicationToApplicationInfoDTO.
/**
* Convert Application to an ApplicationInfoDTO
*
* @param application the application to be converted
* @return ApplicationInfoDTO corresponding to the application
* @throws APIManagementException If an error occurs when getting logged in provider or when getting lightweight API
*/
private static ApplicationInfoDTO fromApplicationToApplicationInfoDTO(Application application) throws APIManagementException {
APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
application = apiProvider.getLightweightApplicationByUUID(application.getUUID());
return ApplicationMappingUtil.fromApplicationToInfoDTO(application);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ApplicationInfoDTO in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromSubscriptionToDTO.
/**
* Converts a SubscribedAPI object into SubscriptionDTO
*
* @param subscription SubscribedAPI object
* @param organization Identifier of the organization
* @return SubscriptionDTO corresponds to SubscribedAPI object
*/
public static SubscriptionDTO fromSubscriptionToDTO(SubscribedAPI subscription, String organization) throws APIManagementException {
String username = RestApiCommonUtil.getLoggedInUsername();
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setSubscriptionId(subscription.getUUID());
APIInfoDTO apiInfo;
Identifier apiId = subscription.getIdentifier();
ApiTypeWrapper apiTypeWrapper;
try {
apiTypeWrapper = apiConsumer.getAPIorAPIProductByUUID(subscription.getIdentifier().getUUID(), organization);
subscriptionDTO.setApiId(subscription.getIdentifier().getUUID());
Set<String> deniedTiers = apiConsumer.getDeniedTiers(organization);
Map<String, Tier> tierMap = APIUtil.getTiers(organization);
if (apiTypeWrapper.isAPIProduct()) {
apiInfo = APIMappingUtil.fromAPIToInfoDTO(apiTypeWrapper.getApiProduct(), organization);
APIMappingUtil.setThrottlePoliciesAndMonetization(apiTypeWrapper.getApiProduct(), apiInfo, deniedTiers, tierMap);
} else {
apiInfo = APIMappingUtil.fromAPIToInfoDTO(apiTypeWrapper.getApi());
APIMappingUtil.setThrottlePoliciesAndMonetization(apiTypeWrapper.getApi(), apiInfo, deniedTiers, tierMap);
}
subscriptionDTO.setApiInfo(apiInfo);
} catch (APIManagementException e) {
if (log.isDebugEnabled()) {
log.debug("User :" + username + " does not have access to the API " + apiId);
}
apiInfo = new APIInfoDTO();
apiInfo.setName(apiId.getName());
apiInfo.setVersion(apiId.getVersion());
subscriptionDTO.setApiInfo(apiInfo);
}
Application application = subscription.getApplication();
application = apiConsumer.getLightweightApplicationByUUID(application.getUUID());
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.ApplicationInfoDTO 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.ApplicationInfoDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromApplicationToInfoDTO.
public static ApplicationInfoDTO fromApplicationToInfoDTO(Application application) {
ApplicationInfoDTO applicationInfoDTO = new ApplicationInfoDTO();
applicationInfoDTO.setApplicationId(application.getId());
applicationInfoDTO.setThrottlingTier(application.getPolicy().getPolicyName());
applicationInfoDTO.setDescription(application.getDescription());
applicationInfoDTO.setLifeCycleStatus(application.getStatus());
applicationInfoDTO.setName(application.getName());
applicationInfoDTO.setSubscriber(application.getCreatedUser());
return applicationInfoDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ApplicationInfoDTO in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromApplicationToInfoDTO.
public static ApplicationInfoDTO fromApplicationToInfoDTO(Application application) {
ApplicationInfoDTO applicationInfoDTO = new ApplicationInfoDTO();
applicationInfoDTO.setApplicationId(application.getUUID());
applicationInfoDTO.setThrottlingPolicy(application.getTier());
applicationInfoDTO.setDescription(application.getDescription());
applicationInfoDTO.setStatus(application.getStatus());
applicationInfoDTO.setName(application.getName());
if (StringUtils.isNotEmpty(application.getGroupId())) {
applicationInfoDTO.setGroups(Arrays.asList(application.getGroupId().split(",")));
}
Map<String, String> applicationAttributes = application.getApplicationAttributes();
applicationInfoDTO.setAttributes(applicationAttributes);
applicationInfoDTO.setSubscriptionCount(application.getSubscriptionCount());
applicationInfoDTO.setOwner(application.getOwner());
return applicationInfoDTO;
}
Aggregations