use of org.wso2.carbon.apimgt.core.models.analytics.APIInfo in project carbon-apimgt by wso2.
the class APIDefinitionFromSwagger20 method generateCompositeApiFromSwaggerResource.
@Override
public CompositeAPI.Builder generateCompositeApiFromSwaggerResource(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("Provided Swagger definition doesn't contain API information");
} else {
String apiName = apiInfo.getTitle();
String apiVersion = apiInfo.getVersion();
String apiDescription = apiInfo.getDescription();
CompositeAPI.Builder apiBuilder = new CompositeAPI.Builder().provider(provider).name(apiName).version(apiVersion).description(apiDescription).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;
}
}
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 apiSummaryList
* @return
*/
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());
apiInfo.setWorkflowStatus(apiSummary.getWorkflowStatus());
apiInfo.setSecurityScheme(mapSecuritySchemeIntToList(apiSummary.getSecurityScheme()));
apiInfoList.add(apiInfo);
}
return apiInfoList;
}
use of org.wso2.carbon.apimgt.core.models.analytics.APIInfo in project carbon-apimgt by wso2.
the class CompositeAPIMappingUtil method toCompositeAPIInfo.
/**
* Converts {@link CompositeAPI} List to an {@link CompositeAPIInfoDTO} List.
*
* @param apiSummaryList
* @return
*/
private static List<CompositeAPIInfoDTO> toCompositeAPIInfo(List<CompositeAPI> apiSummaryList) {
List<CompositeAPIInfoDTO> apiInfoList = new ArrayList<>();
for (CompositeAPI apiSummary : apiSummaryList) {
CompositeAPIInfoDTO apiInfo = new CompositeAPIInfoDTO();
apiInfo.setId(apiSummary.getId());
apiInfo.setContext(apiSummary.getContext());
apiInfo.setDescription(apiSummary.getDescription());
apiInfo.setName(apiSummary.getName());
apiInfo.setProvider(apiSummary.getProvider());
apiInfo.setVersion(apiSummary.getVersion());
apiInfo.setApplicationId(apiSummary.getApplicationId());
apiInfoList.add(apiInfo);
}
return apiInfoList;
}
use of org.wso2.carbon.apimgt.core.models.analytics.APIInfo in project carbon-apimgt by wso2.
the class AnalyticsDAOImplIT method testGetAPIList.
@Test
public void testGetAPIList() throws Exception {
Instant fromTimeStamp = Instant.ofEpochMilli(System.currentTimeMillis());
API testAPI1 = TestUtil.addCustomAPI("Name1", "1.0.0", "sample1");
API testAPI2 = TestUtil.addCustomAPI("Name2", "1.0.0", "sample2");
Instant toTimeStamp = Instant.ofEpochMilli(System.currentTimeMillis() + DELAY_TIME);
AnalyticsDAO analyticsDAO = DAOFactory.getAnalyticsDAO();
List<APIInfo> apiInfoList = analyticsDAO.getAPIInfo(fromTimeStamp, toTimeStamp, null);
Assert.assertEquals(apiInfoList.size(), 2);
APIInfo apiInfo1 = apiInfoList.get(0);
APIInfo apiInfo2 = apiInfoList.get(1);
API result1 = new API.APIBuilder(apiInfo1.getProvider(), apiInfo1.getName(), apiInfo1.getVersion()).build();
API result2 = new API.APIBuilder(apiInfo2.getProvider(), apiInfo2.getName(), apiInfo2.getVersion()).build();
Assert.assertTrue(TestUtil.testAPIEqualsLazy(testAPI1, result1));
Assert.assertTrue(TestUtil.testAPIEqualsLazy(testAPI2, result2));
}
use of org.wso2.carbon.apimgt.core.models.analytics.APIInfo in project carbon-apimgt by wso2.
the class AnalyticsMappingUtil method fromAPICountToListDTO.
/**
* Converts and APICountList to APICountDTO.
*
* @param apiCountList list of APICount objects
* @return corresponding APICountListDTO object
*/
public static APICountListDTO fromAPICountToListDTO(List<APICount> apiCountList, ZoneId zoneId) {
APICountListDTO apiCountListDTO = new APICountListDTO();
List<APICountDTO> apiCountDTOList = new ArrayList<>();
apiCountListDTO.setCount(apiCountList.size());
for (APICount apiInfo : apiCountList) {
apiCountDTOList.add(fromAPICountToDTO(apiInfo, zoneId));
}
apiCountListDTO.setList(apiCountDTOList);
return apiCountListDTO;
}
Aggregations