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;
}
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);
}
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();
}
}
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();
}
}
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());
}
Aggregations