Search in sources :

Example 16 with APIListDTO

use of org.wso2.carbon.apimgt.internal.service.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)

Example 17 with APIListDTO

use of org.wso2.carbon.apimgt.internal.service.dto.APIListDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method apisGetTestCase.

@Test
public void apisGetTestCase() throws Exception {
    String labels = "ZONE_ONE,ZONE_TWO";
    String[] gatewayLabels = labels.split(",");
    List<String> labelList = new ArrayList<String>(Arrays.asList(gatewayLabels));
    APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
    List<API> apiList = new ArrayList<>();
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    Mockito.when(apiMgtAdminService.getAPIsByStatus(labelList, "Published")).thenReturn(apiList);
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    Response response = apisApiService.apisGet(labels, "Published", getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    Integer count = ((APIListDTO) response.getEntity()).getCount();
    Assert.assertEquals(count.intValue(), 3);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.APIListDTO) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with APIListDTO

use of org.wso2.carbon.apimgt.internal.service.dto.APIListDTO in project carbon-apimgt by wso2.

the class CompositeApisApiServiceImpl method compositeApisGet.

@Override
public Response compositeApisGet(Integer limit, Integer offset, String query, String ifNoneMatch, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    CompositeAPIListDTO apiListDTO = null;
    try {
        apiListDTO = CompositeAPIMappingUtil.toCompositeAPIListDTO(RestApiUtil.getConsumer(username).searchCompositeAPIs(query, offset, limit));
        return Response.ok().entity(apiListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving APIs";
        HashMap<String, String> paramList = new HashMap<String, String>();
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) CompositeAPIListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIListDTO)

Example 19 with APIListDTO

use of org.wso2.carbon.apimgt.internal.service.dto.APIListDTO in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method apisGet.

/**
 * Retrives all APIs that qualifies for the given fitering attributes
 *
 * @param limit       maximum APIs to return
 * @param offset      starting position of the pagination
 * @param query       search query
 * @param ifNoneMatch If-None-Match header value
 * @param request     msf4j request object
 * @return a list of qualifying APIs
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response apisGet(Integer limit, Integer offset, String query, String ifNoneMatch, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    APIListDTO apiListDTO = null;
    try {
        apiListDTO = MappingUtil.toAPIListDTO(RestAPIPublisherUtil.getApiPublisher(username).searchAPIs(limit, offset, query));
        return Response.ok().entity(apiListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving APIs";
        HashMap<String, String> paramList = new HashMap<String, String>();
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList, e);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIListDTO)

Example 20 with APIListDTO

use of org.wso2.carbon.apimgt.internal.service.dto.APIListDTO in project carbon-apimgt by wso2.

the class MappingUtilTestCase method toAPIListDTOTest.

@Test
public void toAPIListDTOTest() {
    List<API> apiList = new ArrayList<>();
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    APIListDTO apDTOList = MappingUtil.toAPIListDTO(apiList);
    Assert.assertEquals(apiList.size(), apDTOList.getList().size());
}
Also used : ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.APIListDTO) API(org.wso2.carbon.apimgt.core.models.API) Test(org.testng.annotations.Test)

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