use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method setThrottlePoliciesAndMonetization.
public static void setThrottlePoliciesAndMonetization(API api, APIInfoDTO apiInfoDTO, Set<String> deniedTiers, Map<String, Tier> tierMap) {
Set<Tier> throttlingPolicies = new HashSet<Tier>();
List<String> throttlingPolicyNames = new ArrayList<>();
Set<Tier> apiTiers = api.getAvailableTiers();
for (Tier currentTier : apiTiers) {
if (!deniedTiers.contains(currentTier.getName())) {
throttlingPolicies.add(currentTier);
throttlingPolicyNames.add(currentTier.getName());
}
}
int free = 0, commercial = 0;
for (Tier tier : throttlingPolicies) {
tier = tierMap.get(tier.getName());
if (RestApiConstants.FREE.equalsIgnoreCase(tier.getTierPlan())) {
free = free + 1;
} else if (RestApiConstants.COMMERCIAL.equalsIgnoreCase(tier.getTierPlan())) {
commercial = commercial + 1;
}
}
if (free > 0 && commercial == 0) {
apiInfoDTO.setMonetizationLabel(RestApiConstants.FREE);
} else if (free == 0 && commercial > 0) {
apiInfoDTO.setMonetizationLabel(RestApiConstants.PAID);
} else if (free > 0 && commercial > 0) {
apiInfoDTO.setMonetizationLabel(RestApiConstants.FREEMIUM);
}
apiInfoDTO.setThrottlingPolicies(throttlingPolicyNames);
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method fromAPIToInfoDTO.
/**
* Creates a minimal DTO representation of an API object
*
* @param api API object
* @return a minimal representation DTO
*/
static APIInfoDTO fromAPIToInfoDTO(API api) throws APIManagementException {
APIInfoDTO apiInfoDTO = new APIInfoDTO();
apiInfoDTO.setDescription(api.getDescription());
String context = api.getContextTemplate();
if (context.endsWith("/" + RestApiConstants.API_VERSION_PARAM)) {
context = context.replace("/" + RestApiConstants.API_VERSION_PARAM, "");
}
apiInfoDTO.setContext(context);
apiInfoDTO.setId(api.getUUID());
APIIdentifier apiId = api.getId();
apiInfoDTO.setName(apiId.getApiName());
apiInfoDTO.setVersion(apiId.getVersion());
apiInfoDTO.setProvider(apiId.getProviderName());
apiInfoDTO.setLifeCycleStatus(api.getStatus());
apiInfoDTO.setType(api.getType());
apiInfoDTO.setAvgRating(String.valueOf(api.getRating()));
String providerName = api.getId().getProviderName();
apiInfoDTO.setProvider(APIUtil.replaceEmailDomainBack(providerName));
APIBusinessInformationDTO apiBusinessInformationDTO = new APIBusinessInformationDTO();
apiBusinessInformationDTO.setBusinessOwner(api.getBusinessOwner());
apiBusinessInformationDTO.setBusinessOwnerEmail(api.getBusinessOwnerEmail());
apiBusinessInformationDTO.setTechnicalOwner(api.getTechnicalOwner());
apiBusinessInformationDTO.setTechnicalOwnerEmail(api.getTechnicalOwnerEmail());
apiInfoDTO.setBusinessInformation(apiBusinessInformationDTO);
apiInfoDTO.setCreatedTime(api.getCreatedTime());
// }
if (!StringUtils.isBlank(api.getThumbnailUrl())) {
apiInfoDTO.setThumbnailUri(api.getThumbnailUrl());
}
apiInfoDTO.setAdvertiseInfo(extractAdvertiseInfo(api));
String apiTenant = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(api.getId().getProviderName()));
String subscriptionAvailability = api.getSubscriptionAvailability();
String subscriptionAllowedTenants = api.getSubscriptionAvailableTenants();
apiInfoDTO.setIsSubscriptionAvailable(isSubscriptionAvailable(apiTenant, subscriptionAvailability, subscriptionAllowedTenants));
apiInfoDTO.setGatewayVendor(api.getGatewayVendor());
return apiInfoDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.
the class ServicesApiServiceImpl method getServiceUsage.
@Override
public Response getServiceUsage(String serviceId, MessageContext messageContext) {
String userName = RestApiCommonUtil.getLoggedInUsername();
int tenantId = APIUtil.getTenantId(userName);
try {
List<API> apiList = serviceCatalog.getServiceUsage(serviceId, tenantId);
if (apiList != null) {
APIListDTO apiListDTO = new APIListDTO();
List<APIInfoDTO> apiInfoDTOList = new ArrayList<>();
for (API api : apiList) {
apiInfoDTOList.add(ServiceEntryMappingUtil.fromAPIToAPIInfoDTO(api));
}
apiListDTO.setList(apiInfoDTOList);
apiListDTO.setCount(apiList.size());
return Response.ok().entity(apiListDTO).build();
} else {
RestApiUtil.handleResourceNotFoundError("Service", serviceId, log);
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving API usage of service";
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.
the class ServiceEntryMappingUtil method fromAPIToAPIInfoDTO.
public static APIInfoDTO fromAPIToAPIInfoDTO(API api) {
APIInfoDTO apiInfoDTO = new APIInfoDTO();
apiInfoDTO.setName(api.getId().getApiName());
apiInfoDTO.setVersion(api.getId().getVersion());
apiInfoDTO.setContext(api.getContext());
apiInfoDTO.setId(api.getUuid());
apiInfoDTO.setProvider(api.getId().getProviderName());
return apiInfoDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.
the class APIInfoMappingUtil method fromAPIInfoToDTO.
/**
* Converts a APIIdentifier object into APIInfoDTO
*
* @param apiId APIIdentifier object
* @return APIInfoDTO corresponds to APIIdentifier object
*/
private static APIInfoDTO fromAPIInfoToDTO(APIIdentifier apiId) throws UnsupportedEncodingException {
APIInfoDTO apiInfoDTO = new APIInfoDTO();
APIIdentifier apiIdEmailReplacedBack = new APIIdentifier(APIUtil.replaceEmailDomainBack(apiId.getProviderName()).replace(RestApiConstants.API_ID_DELIMITER, RestApiConstants.URL_ENCODED_API_ID_DELIMITER), URLEncoder.encode(apiId.getApiName(), RestApiConstants.CHARSET).replace(RestApiConstants.API_ID_DELIMITER, RestApiConstants.URL_ENCODED_API_ID_DELIMITER), apiId.getVersion().replace(RestApiConstants.API_ID_DELIMITER, RestApiConstants.URL_ENCODED_API_ID_DELIMITER));
apiInfoDTO.setName(apiIdEmailReplacedBack.getApiName());
apiInfoDTO.setVersion(apiIdEmailReplacedBack.getVersion());
apiInfoDTO.setProvider(apiIdEmailReplacedBack.getProviderName());
return apiInfoDTO;
}
Aggregations