Search in sources :

Example 41 with APIInfo

use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.

the class AnalyticsMappingUtilTestCase method fromAPIInfoListToDTOTest.

@Test
public void fromAPIInfoListToDTOTest() {
    List<APIInfo> apiInfoList = new ArrayList<>();
    apiInfoList.add(SampleTestObjectCreator.createRandomAPIInfoObject());
    apiInfoList.add(SampleTestObjectCreator.createRandomAPIInfoObject());
    apiInfoList.add(SampleTestObjectCreator.createRandomAPIInfoObject());
    APIInfoListDTO apiInfoListDTO = AnalyticsMappingUtil.fromAPIInfoListToDTO(apiInfoList, ZoneOffset.UTC);
    Assert.assertEquals(apiInfoList.size(), apiInfoListDTO.getList().size());
    for (int i = 0; i < apiInfoList.size(); i++) {
        Assert.assertEquals(epochToISO8601DateTime(apiInfoList.get(i).getCreatedTime(), ZoneOffset.UTC), apiInfoListDTO.getList().get(i).getTime());
        Assert.assertEquals(apiInfoList.get(i).getName(), apiInfoListDTO.getList().get(i).getName());
        Assert.assertEquals(apiInfoList.get(i).getContext(), apiInfoListDTO.getList().get(i).getContext());
        Assert.assertEquals(apiInfoList.get(i).getDescription(), apiInfoListDTO.getList().get(i).getDescription());
        Assert.assertEquals(apiInfoList.get(i).getLifeCycleStatus(), apiInfoListDTO.getList().get(i).getLifeCycleStatus());
        Assert.assertEquals(apiInfoList.get(i).getProvider(), apiInfoListDTO.getList().get(i).getProvider());
        Assert.assertEquals(apiInfoList.get(i).getVersion(), apiInfoListDTO.getList().get(i).getVersion());
        Assert.assertEquals(apiInfoList.get(i).getId(), apiInfoListDTO.getList().get(i).getId());
    }
}
Also used : APIInfo(org.wso2.carbon.apimgt.core.models.analytics.APIInfo) ArrayList(java.util.ArrayList) APIInfoListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoListDTO) Test(org.testng.annotations.Test)

Example 42 with APIInfo

use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.

the class ApiApiServiceImpl method apiListGet.

/**
 * Get list of API Info
 *
 * @param startTime Filter for start time stamp
 * @param endTime   Filter for end time stamp
 * @param createdBy Filter for created user
 * @param request   MSF4J request
 * @return API List
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response apiListGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        log.debug("Retrieving API information. [From: {} To: {} Created By:{} ]", startTime, endTime, createdBy);
        Analyzer analyzer = RestApiUtil.getAnalyzer(username);
        ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
        List<APIInfo> apiInfoList = analyzer.getAPIInfo(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
        APIInfoListDTO apiInfoListDTO = AnalyticsMappingUtil.fromAPIInfoListToDTO(apiInfoList, requestTimezone);
        return Response.ok().entity(apiInfoListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API information";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : ZoneId(java.time.ZoneId) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIInfo(org.wso2.carbon.apimgt.core.models.analytics.APIInfo) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer) APIInfoListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoListDTO)

Example 43 with APIInfo

use of org.wso2.carbon.apimgt.api.model.APIInfo in project carbon-apimgt by wso2.

the class AnalyticsMappingUtil method fromAPIInfoToDTO.

private static APIInfoDTO fromAPIInfoToDTO(APIInfo apiInfo, ZoneId zoneId) {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    apiInfoDTO.setId(apiInfo.getId());
    apiInfoDTO.setName(apiInfo.getName());
    apiInfoDTO.setVersion(apiInfo.getVersion());
    apiInfoDTO.setContext(apiInfo.getContext());
    apiInfoDTO.setDescription(apiInfo.getDescription());
    apiInfoDTO.setLifeCycleStatus(apiInfo.getLifeCycleStatus());
    apiInfoDTO.setProvider(apiInfo.getProvider());
    apiInfoDTO.setWorkflowStatus(apiInfo.getWorkflowStatus());
    apiInfoDTO.setTime(epochToISO8601DateTime(apiInfo.getCreatedTime(), zoneId));
    return apiInfoDTO;
}
Also used : APIInfoDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoDTO)

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