use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method fromAPIListToInfoDTO.
/**
* Converts a List object of APIs into Info DTO List.
*
* @param apiList List of APIs
* @return APIListDTO object containing APIDTOs
*/
public static APIListDTO fromAPIListToInfoDTO(List<API> apiList) throws APIManagementException {
APIListDTO apiListDTO = new APIListDTO();
List<APIInfoDTO> apiInfoDTOs = apiListDTO.getList();
for (API api : apiList) {
apiInfoDTOs.add(fromAPIToInfoDTO(api));
}
apiListDTO.setCount(apiInfoDTOs.size());
return apiListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.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
*/
public static APIInfoDTO fromAPIToInfoDTO(API api) {
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.setType(api.getType());
String providerName = api.getId().getProviderName();
apiInfoDTO.setProvider(APIUtil.replaceEmailDomainBack(providerName));
apiInfoDTO.setLifeCycleStatus(api.getStatus());
apiInfoDTO.setHasThumbnail(!StringUtils.isBlank(api.getThumbnailUrl()));
if (api.getAudience() != null) {
apiInfoDTO.setAudience(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoDTO.AudienceEnum.valueOf(api.getAudience()));
}
if (api.getCreatedTime() != null) {
Date createdTime = new Date(Long.parseLong(api.getCreatedTime()));
apiInfoDTO.setCreatedTime(String.valueOf(createdTime.getTime()));
}
if (api.getLastUpdated() != null) {
Date lastUpdatedTime = api.getLastUpdated();
apiInfoDTO.setUpdatedTime(String.valueOf(lastUpdatedTime.getTime()));
}
apiInfoDTO.setAdvertiseOnly(api.isAdvertiseOnly());
if (api.getAdditionalProperties() != null) {
JSONObject additionalProperties = api.getAdditionalProperties();
List<APIInfoAdditionalPropertiesDTO> additionalPropertiesList = new ArrayList<>();
Map<String, APIInfoAdditionalPropertiesMapDTO> additionalPropertiesMap = new HashMap<>();
for (Object propertyKey : additionalProperties.keySet()) {
APIInfoAdditionalPropertiesDTO additionalPropertiesDTO = new APIInfoAdditionalPropertiesDTO();
APIInfoAdditionalPropertiesMapDTO apiInfoAdditionalPropertiesMapDTO = new APIInfoAdditionalPropertiesMapDTO();
String key = (String) propertyKey;
int index = key.lastIndexOf(APIConstants.API_RELATED_CUSTOM_PROPERTIES_SURFIX);
additionalPropertiesDTO.setValue((String) additionalProperties.get(key));
apiInfoAdditionalPropertiesMapDTO.setValue((String) additionalProperties.get(key));
if (index > 0) {
additionalPropertiesDTO.setName(key.substring(0, index));
apiInfoAdditionalPropertiesMapDTO.setName(key.substring(0, index));
additionalPropertiesDTO.setDisplay(true);
} else {
additionalPropertiesDTO.setName(key);
apiInfoAdditionalPropertiesMapDTO.setName(key);
additionalPropertiesDTO.setDisplay(false);
}
apiInfoAdditionalPropertiesMapDTO.setDisplay(false);
additionalPropertiesMap.put(key, apiInfoAdditionalPropertiesMapDTO);
additionalPropertiesList.add(additionalPropertiesDTO);
}
apiInfoDTO.setAdditionalProperties(additionalPropertiesList);
apiInfoDTO.setAdditionalPropertiesMap(additionalPropertiesMap);
apiInfoDTO.setGatewayVendor(api.getGatewayVendor());
}
return apiInfoDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.
the class APIInfoMappingUtil method fromAPIInfoListToDTO.
/**
* Converts a List object of APIIdentifiers into a DTO
*
* @param apiIds a list of APIIdentifier objects
* @return APIInfoListDTO object containing APIInfoDTOs
*/
public static APIInfoListDTO fromAPIInfoListToDTO(List<APIIdentifier> apiIds) throws UnsupportedEncodingException {
APIInfoListDTO apiInfoListDTO = new APIInfoListDTO();
List<APIInfoDTO> apiInfoDTOs = apiInfoListDTO.getList();
if (apiInfoDTOs == null) {
apiInfoDTOs = new ArrayList<>();
apiInfoListDTO.setList(apiInfoDTOs);
}
for (APIIdentifier apiId : apiIds) {
apiInfoDTOs.add(fromAPIInfoToDTO(apiId));
}
apiInfoListDTO.setCount(apiInfoDTOs.size());
return apiInfoListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method fromAPIListToDTO.
/**
* Converts a List object of APIs into a DTO
*
* @param apiList List of APIs
* @return APIListDTO object containing APIDTOs
* @throws APIManagementException
*/
public static APIListDTO fromAPIListToDTO(List<Object> apiList, String organization) throws APIManagementException {
APIListDTO apiListDTO = new APIListDTO();
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
Set<String> deniedTiers = apiConsumer.getDeniedTiers(organization);
Map<String, Tier> tierMap = APIUtil.getTiers(organization);
List<APIInfoDTO> apiInfoDTOs = apiListDTO.getList();
if (apiList != null) {
for (Object api : apiList) {
APIInfoDTO apiInfoDTO = null;
if (api instanceof API) {
API api1 = (API) api;
apiInfoDTO = fromAPIToInfoDTO((API) api);
setThrottlePoliciesAndMonetization(api1, apiInfoDTO, deniedTiers, tierMap);
} else if (api instanceof APIProduct) {
APIProduct api1 = (APIProduct) api;
apiInfoDTO = fromAPIToInfoDTO((API) api);
setThrottlePoliciesAndMonetization(api1, apiInfoDTO, deniedTiers, tierMap);
}
apiInfoDTOs.add(apiInfoDTO);
}
}
apiListDTO.setCount(apiInfoDTOs.size());
return apiListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoDTO in project carbon-apimgt by wso2.
the class APIMappingUtil method setThrottlePoliciesAndMonetization.
public static void setThrottlePoliciesAndMonetization(APIProduct apiProduct, APIInfoDTO apiInfoDTO, Set<String> deniedTiers, Map<String, Tier> tierMap) {
Set<Tier> throttlingPolicies = new HashSet<Tier>();
List<String> throttlingPolicyNames = new ArrayList<>();
Set<Tier> apiTiers = apiProduct.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);
}
Aggregations