Search in sources :

Example 6 with APIListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIListDTO in project carbon-apimgt by wso2.

the class CompositeAPIMappingUtil method toCompositeAPIListDTO.

/**
 * Converts API list to CompositeAPIListDTO list.
 *
 * @param apisResult List of APIs
 * @return CompositeAPIListDTO object
 */
public static CompositeAPIListDTO toCompositeAPIListDTO(List<CompositeAPI> apisResult) {
    CompositeAPIListDTO apiListDTO = new CompositeAPIListDTO();
    apiListDTO.setCount(apisResult.size());
    // apiListDTO.setNext(next);
    // apiListDTO.setPrevious(previous);
    apiListDTO.setList(toCompositeAPIInfo(apisResult));
    return apiListDTO;
}
Also used : CompositeAPIListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIListDTO)

Example 7 with APIListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIListDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method toAPIListDTO.

/**
 * Converts {@code List<API>} to {@link APIListDTO} DTO.
 *
 * @param apisResult List of APIs
 * @return APIListDTO
 */
public static APIListDTO toAPIListDTO(List<API> apisResult) {
    APIListDTO apiListDTO = new APIListDTO();
    apiListDTO.setCount(apisResult.size());
    // apiListDTO.setNext(next);
    // apiListDTO.setPrevious(previous);
    apiListDTO.setList(toAPIInfo(apisResult));
    return apiListDTO;
}
Also used : APIListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO)

Example 8 with APIListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIListDTO in project carbon-apimgt by wso2.

the class APIMappingUtilTestCase method testAPIListDTO.

@Test
public void testAPIListDTO() throws APIManagementException {
    String api1Id = UUID.randomUUID().toString();
    Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
    Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
    API api1 = createApi("provider1", api1Id, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
    String api2Id = UUID.randomUUID().toString();
    Endpoint api2SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd123").build();
    Endpoint api2ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef123").build();
    API api2 = createApi("provider1", api2Id, "testapi2", "1.0.0", "Test API 2 - version 1.0.0", createEndpointTypeToIdMap(api2SandBoxEndpointId, api2ProdEndpointId)).build();
    List<API> apiList = new ArrayList<>();
    apiList.add(api1);
    apiList.add(api2);
    APIMappingUtil apiMappingUtil = new APIMappingUtil();
    APIListDTO apiListDTO = apiMappingUtil.toAPIListDTO(apiList);
    Assert.assertEquals(apiListDTO.getList().get(0).getName(), "testapi1");
    Assert.assertEquals(apiListDTO.getList().get(1).getName(), "testapi2");
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 9 with APIListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIListDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method apisGet.

/**
 * Retrieve a list of APIs with given gateway labels and status.
 *
 * @param labels Gateway labels
 * @param status Lifecycle status
 * @param request msf4j request object
 * @return 200 OK if the opration was successful
 * @throws NotFoundException If failed to retrieve APIs
 */
@Override
public Response apisGet(String labels, String status, Request request) throws NotFoundException {
    APIListDTO apiListDTO;
    try {
        APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
        if (labels != null && !labels.isEmpty()) {
            String[] gatewayLabels = labels.split(",");
            List<String> labelList = new ArrayList<String>(Arrays.asList(gatewayLabels));
            if (status != null && !status.isEmpty()) {
                apiListDTO = MappingUtil.toAPIListDTO(adminService.getAPIsByStatus(labelList, status));
                return Response.ok().entity(apiListDTO).build();
            } else {
                apiListDTO = MappingUtil.toAPIListDTO(adminService.getAPIsByGatewayLabel(labelList));
                return Response.ok().entity(apiListDTO).build();
            }
        } else {
            apiListDTO = new APIListDTO();
            return Response.ok().entity(apiListDTO).build();
        }
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving APIs";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.APIListDTO)

Example 10 with APIListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIListDTO in project carbon-apimgt by wso2.

the class APIMappingUtil method fromAPIListToInfoDTO.

/**
 * Converts a List object of APIs into Info DTO List.
 *
 * @param apiList List of APIs
 * @return APIListDTO object containing APIDTOs
 */
public static APIListDTO fromAPIListToInfoDTO(List<API> apiList) throws APIManagementException {
    APIListDTO apiListDTO = new APIListDTO();
    List<APIInfoDTO> apiInfoDTOs = apiListDTO.getList();
    for (API api : apiList) {
        apiInfoDTOs.add(fromAPIToInfoDTO(api));
    }
    apiListDTO.setCount(apiInfoDTOs.size());
    return apiListDTO;
}
Also used : APIListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIListDTO) API(org.wso2.carbon.apimgt.api.model.API) APIRevisionAPIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIRevisionAPIInfoDTO) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoDTO)

Aggregations

ArrayList (java.util.ArrayList)13 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)8 API (org.wso2.carbon.apimgt.core.models.API)7 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)6 APIListDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.APIListDTO)5 HashMap (java.util.HashMap)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)4 API (org.wso2.carbon.apimgt.api.model.API)4 APIListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.APIListDTO)4 JSONObject (org.json.simple.JSONObject)3 APIListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO)3 File (java.io.File)2 Set (java.util.Set)2 Test (org.junit.Test)2 Test (org.testng.annotations.Test)2 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)2 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)2 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)2 APIMgtEntityImportExportException (org.wso2.carbon.apimgt.core.exception.APIMgtEntityImportExportException)2 APIDetails (org.wso2.carbon.apimgt.core.models.APIDetails)2