use of org.wso2.carbon.apimgt.core.models.analytics.APIInfo in project carbon-apimgt by wso2.
the class AnalyticsMappingUtil method fromAPIInfoListToDTO.
/**
* Converts and APIInfoList to APIInfoListDTO.
*
* @param apiInfoList list of ApiInfo objects
* @return corresponding APIInfoListDTO object
*/
public static APIInfoListDTO fromAPIInfoListToDTO(List<APIInfo> apiInfoList, ZoneId zoneId) {
APIInfoListDTO apiInfoListDTO = new APIInfoListDTO();
List<APIInfoDTO> apiInfoDTOList = new ArrayList<>();
apiInfoListDTO.setCount(apiInfoList.size());
for (APIInfo apiInfo : apiInfoList) {
apiInfoDTOList.add(fromAPIInfoToDTO(apiInfo, zoneId));
}
apiInfoListDTO.setList(apiInfoDTOList);
return apiInfoListDTO;
}
use of org.wso2.carbon.apimgt.core.models.analytics.APIInfo in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createRandomAPIInfoObject.
/**
* Create Random APICount Object.
*
* @return Random APICount Object
*/
public static APIInfo createRandomAPIInfoObject() {
APIInfo apiInfo = new APIInfo();
apiInfo.setId(UUID.randomUUID().toString());
apiInfo.setName(UUID.randomUUID().toString());
apiInfo.setDescription(UUID.randomUUID().toString());
apiInfo.setContext(UUID.randomUUID().toString());
apiInfo.setVersion(UUID.randomUUID().toString());
apiInfo.setProvider(UUID.randomUUID().toString());
apiInfo.setLifeCycleStatus(UUID.randomUUID().toString());
apiInfo.setWorkflowStatus(UUID.randomUUID().toString());
apiInfo.setCreatedTime(ThreadLocalRandom.current().nextLong());
return apiInfo;
}
use of org.wso2.carbon.apimgt.core.models.analytics.APIInfo in project carbon-apimgt by wso2.
the class MappingUtil method toAPIInfo.
/**
* Converts {@link API} List to an {@link APIInfoDTO} List.
*
* @param apiList
* @return
*/
private static List<APIInfoDTO> toAPIInfo(List<API> apiList) {
List<APIInfoDTO> apiInfoList = new ArrayList<APIInfoDTO>();
for (API api : apiList) {
APIInfoDTO apiInfo = new APIInfoDTO();
apiInfo.setId(api.getId());
apiInfo.setContext(api.getContext());
apiInfo.setName(api.getName());
apiInfo.setLifeCycleStatus(api.getLifeCycleStatus());
apiInfo.setVersion(api.getVersion());
apiInfo.setSecurityScheme(api.getSecurityScheme());
for (String threatProtectionPolicyId : api.getThreatProtectionPolicies()) {
apiInfo.addThreatProtectionPoliciesItem(threatProtectionPolicyId);
}
apiInfoList.add(apiInfo);
}
return apiInfoList;
}
use of org.wso2.carbon.apimgt.core.models.analytics.APIInfo in project carbon-apimgt by wso2.
the class APIMappingUtil method toAPIInfo.
/**
* Converts {@link API} List to an {@link APIInfoDTO} List.
*
* @param apiSummaryList List of APIs
* @return List of APIInfoDTO
*/
private static List<APIInfoDTO> toAPIInfo(List<API> apiSummaryList) {
List<APIInfoDTO> apiInfoList = new ArrayList<APIInfoDTO>();
for (API apiSummary : apiSummaryList) {
APIInfoDTO apiInfo = new APIInfoDTO();
apiInfo.setId(apiSummary.getId());
apiInfo.setContext(apiSummary.getContext());
apiInfo.setDescription(apiSummary.getDescription());
apiInfo.setName(apiSummary.getName());
apiInfo.setProvider(apiSummary.getProvider());
apiInfo.setLifeCycleStatus(apiSummary.getLifeCycleStatus());
apiInfo.setVersion(apiSummary.getVersion());
apiInfoList.add(apiInfo);
}
return apiInfoList;
}
use of org.wso2.carbon.apimgt.core.models.analytics.APIInfo in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method generateApiFromSwaggerResource.
/**
* return API Object
*
* @param provider Provider of the API.
* @param apiDefinition API definition as string
* @return API object.
* @throws APIManagementException If failed to generate API from swagger.
*/
@Override
public API.APIBuilder generateApiFromSwaggerResource(String provider, String apiDefinition) throws APIManagementException {
SwaggerParser swaggerParser = new SwaggerParser();
Swagger swagger = swaggerParser.parse(apiDefinition);
if (swagger == null) {
throw new APIManagementException("Swagger could not be generated from provided API definition");
}
Info apiInfo = swagger.getInfo();
if (apiInfo == null) {
throw new APIManagementException("Swagger doesn't contains the info");
} else {
String apiName = apiInfo.getTitle();
String apiVersion = apiInfo.getVersion();
String apiDescription = apiInfo.getDescription();
Contact contact = apiInfo.getContact();
BusinessInformation businessInformation = new BusinessInformation();
if (contact != null) {
businessInformation.setBusinessOwner(contact.getName());
businessInformation.setBusinessOwnerEmail(contact.getEmail());
}
API.APIBuilder apiBuilder = new API.APIBuilder(provider, apiName, apiVersion);
apiBuilder.businessInformation(businessInformation);
apiBuilder.description(apiDescription);
apiBuilder.context(swagger.getBasePath());
List<APIResource> apiResourceList = parseSwaggerAPIResources(new StringBuilder(apiDefinition));
Map<String, UriTemplate> uriTemplateMap = new HashMap();
for (APIResource apiResource : apiResourceList) {
uriTemplateMap.put(apiResource.getUriTemplate().getTemplateId(), apiResource.getUriTemplate());
}
apiBuilder.uriTemplates(uriTemplateMap);
apiBuilder.id(UUID.randomUUID().toString());
return apiBuilder;
}
}
Aggregations