Search in sources :

Example 1 with APIInfo

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;
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) APIResource(org.wso2.carbon.apimgt.core.models.APIResource) Info(io.swagger.models.Info) ServiceMethodInfo(org.wso2.msf4j.ServiceMethodInfo) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) SwaggerParser(io.swagger.parser.SwaggerParser) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) Swagger(io.swagger.models.Swagger) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI)

Example 2 with 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 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;
}
Also used : ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIInfoDTO)

Example 3 with APIInfo

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;
}
Also used : ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) CompositeAPIInfoDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIInfoDTO)

Example 4 with APIInfo

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));
}
Also used : AnalyticsDAO(org.wso2.carbon.apimgt.core.dao.AnalyticsDAO) Instant(java.time.Instant) APIInfo(org.wso2.carbon.apimgt.core.models.analytics.APIInfo) API(org.wso2.carbon.apimgt.core.models.API) Test(org.testng.annotations.Test)

Example 5 with APIInfo

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;
}
Also used : APICount(org.wso2.carbon.apimgt.core.models.analytics.APICount) APICountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO) ArrayList(java.util.ArrayList) APICountDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountDTO)

Aggregations

ArrayList (java.util.ArrayList)9 APIInfo (org.wso2.carbon.apimgt.core.models.analytics.APIInfo)7 API (org.wso2.carbon.apimgt.core.models.API)5 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)4 Test (org.testng.annotations.Test)3 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)3 APIInfoListDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoListDTO)3 Info (io.swagger.models.Info)2 Swagger (io.swagger.models.Swagger)2 SwaggerParser (io.swagger.parser.SwaggerParser)2 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)2 AnalyticsDAO (org.wso2.carbon.apimgt.core.dao.AnalyticsDAO)2 APIResource (org.wso2.carbon.apimgt.core.models.APIResource)2 UriTemplate (org.wso2.carbon.apimgt.core.models.UriTemplate)2 APIInfoDTO (org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoDTO)2 ServiceMethodInfo (org.wso2.msf4j.ServiceMethodInfo)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Contact (io.swagger.models.Contact)1