Search in sources :

Example 1 with APIInfo

use of org.wso2.carbon.apimgt.api.model.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.api.model.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.api.model.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.api.model.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.api.model.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

APIInfo (org.wso2.carbon.apimgt.api.model.APIInfo)20 ArrayList (java.util.ArrayList)17 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)17 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)16 HashMap (java.util.HashMap)7 APIDefinitionValidationResponse (org.wso2.carbon.apimgt.api.APIDefinitionValidationResponse)7 APIInfo (org.wso2.carbon.apimgt.core.models.analytics.APIInfo)7 API (org.wso2.carbon.apimgt.core.models.API)5 WSDLValidationResponse (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse)5 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 Response (javax.ws.rs.core.Response)4 HttpResponse (org.apache.http.HttpResponse)4 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 APIStateChangeResponse (org.wso2.carbon.apimgt.api.model.APIStateChangeResponse)4 Documentation (org.wso2.carbon.apimgt.api.model.Documentation)4 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)4 Tier (org.wso2.carbon.apimgt.api.model.Tier)4 APIDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO)4 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3