Search in sources :

Example 11 with APIListDTO

use of org.wso2.carbon.apimgt.rest.api.store.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 12 with APIListDTO

use of org.wso2.carbon.apimgt.rest.api.store.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 13 with APIListDTO

use of org.wso2.carbon.apimgt.rest.api.store.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 14 with APIListDTO

use of org.wso2.carbon.apimgt.rest.api.store.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)

Example 15 with APIListDTO

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

the class ApisApiServiceImpl method apisGet.

/**
 * Retrieves APIs qualifying under given search condition
 *
 * @param limit       maximum number of APIs returns
 * @param offset      starting index
 * @param labels      Labels of the store for which the apis need to be retrieved
 * @param query       search condition
 * @param ifNoneMatch If-None-Match header value
 * @param request     msf4j request object
 * @return matched APIs for the given search condition
 */
@Override
public Response apisGet(Integer limit, Integer offset, String labels, String query, String ifNoneMatch, Request request) throws NotFoundException {
    List<API> apisResult = null;
    APIListDTO apiListDTO = null;
    try {
        String username = RestApiUtil.getLoggedInUsername(request);
        APIStore apiStore = RestApiUtil.getConsumer(username);
        List<String> labelList = new ArrayList<>();
        if (labels != null) {
            labelList = Arrays.asList(labels.split(","));
        }
        apisResult = apiStore.searchAPIsByStoreLabels(query, offset, limit, labelList);
        // convert API
        apiListDTO = APIMappingUtil.toAPIListDTO(apisResult);
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving APIs ";
        HashMap<String, String> paramList = new HashMap<String, String>();
        paramList.put(APIMgtConstants.ExceptionsConstants.API_NAME, query);
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
    return Response.ok().entity(apiListDTO).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) ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.APIListDTO) API(org.wso2.carbon.apimgt.core.models.API) APIStore(org.wso2.carbon.apimgt.core.api.APIStore)

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