Search in sources :

Example 6 with APIListDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.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.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.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.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.dto.APIListDTO in project carbon-apimgt by wso2.

the class MappingUtil method toAPIListDTO.

/**
 * Converts API list to APIListDTO list.
 *
 * @param apisList List of APIs
 * @return APIListDTO object
 */
public static APIListDTO toAPIListDTO(List<API> apisList) {
    APIListDTO apiListDTO = new APIListDTO();
    apiListDTO.setCount(apisList.size());
    apiListDTO.setList(toAPIInfo(apisList));
    return apiListDTO;
}
Also used : APIListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.APIListDTO)

Aggregations

ArrayList (java.util.ArrayList)8 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 APIListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.APIListDTO)4 HashMap (java.util.HashMap)3 APIListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO)3 Test (org.junit.Test)2 Test (org.testng.annotations.Test)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 FileBasedApiImportExportManager (org.wso2.carbon.apimgt.rest.api.publisher.utils.FileBasedApiImportExportManager)2 CompositeAPIListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIListDTO)2 Response (javax.ws.rs.core.Response)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)1 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)1