Search in sources :

Example 1 with CompositeAPIListDTO

use of org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIListDTO 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 2 with CompositeAPIListDTO

use of org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIListDTO 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 3 with CompositeAPIListDTO

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

the class CompositeAPIMappingUtilTestCase method testToCompositeAPIListDTO.

@Test
public void testToCompositeAPIListDTO() {
    List<CompositeAPI> apisResult = new ArrayList<>();
    CompositeAPI comp1 = SampleTestObjectCreator.createCompositeAPIModelBuilder().name("newComp1").build();
    CompositeAPI comp2 = SampleTestObjectCreator.createCompositeAPIModelBuilder().name("newComp2").build();
    apisResult.add(comp1);
    apisResult.add(comp2);
    CompositeAPIListDTO compositeAPIListDTO = CompositeAPIMappingUtil.toCompositeAPIListDTO(apisResult);
    assertEquals(compositeAPIListDTO.getCount(), (Integer) apisResult.size());
    assertEquals(comp1.getId(), compositeAPIListDTO.getList().get(0).getId());
    assertEquals(comp1.getName(), compositeAPIListDTO.getList().get(0).getName());
    assertEquals(comp1.getProvider(), compositeAPIListDTO.getList().get(0).getProvider());
    assertEquals(comp1.getVersion(), compositeAPIListDTO.getList().get(0).getVersion());
    assertEquals(comp1.getContext(), compositeAPIListDTO.getList().get(0).getContext());
    assertEquals(comp1.getDescription(), compositeAPIListDTO.getList().get(0).getDescription());
    assertEquals(comp1.getApplicationId(), compositeAPIListDTO.getList().get(0).getApplicationId());
    assertEquals(comp2.getId(), compositeAPIListDTO.getList().get(1).getId());
    assertEquals(comp2.getName(), compositeAPIListDTO.getList().get(1).getName());
    assertEquals(comp2.getProvider(), compositeAPIListDTO.getList().get(1).getProvider());
    assertEquals(comp2.getVersion(), compositeAPIListDTO.getList().get(1).getVersion());
    assertEquals(comp2.getContext(), compositeAPIListDTO.getList().get(1).getContext());
    assertEquals(comp2.getDescription(), compositeAPIListDTO.getList().get(1).getDescription());
    assertEquals(comp2.getApplicationId(), compositeAPIListDTO.getList().get(1).getApplicationId());
}
Also used : ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) CompositeAPIListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIListDTO) Test(org.testng.annotations.Test)

Aggregations

CompositeAPIListDTO (org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIListDTO)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.testng.annotations.Test)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1