Search in sources :

Example 6 with APIInfo

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

Example 7 with APIInfo

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;
}
Also used : APIInfo(org.wso2.carbon.apimgt.core.models.analytics.APIInfo)

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

Example 9 with APIInfo

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

Example 10 with APIInfo

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;
    }
}
Also used : BusinessInformation(org.wso2.carbon.apimgt.core.models.BusinessInformation) 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) Contact(io.swagger.models.Contact) 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) API(org.wso2.carbon.apimgt.core.models.API)

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