Search in sources :

Example 1 with APICategoryListDTO

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

the class APICategoryMappingUtilTestCase method testCategoryDescription.

@Test
public void testCategoryDescription() throws Exception {
    APICategory category = new APICategory();
    String description = "sample description";
    category.setDescription(description);
    category.setName("test");
    List<APICategory> categories = new ArrayList<APICategory>();
    categories.add(category);
    APICategoryListDTO ListDto = APICategoryMappingUtil.fromCategoryListToCategoryListDTO(categories);
    APICategoryDTO dto = ListDto.getList().get(0);
    Assert.assertEquals("Category description mismatch", description, dto.getDescription());
}
Also used : ArrayList(java.util.ArrayList) APICategoryDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APICategoryDTO) APICategory(org.wso2.carbon.apimgt.api.model.APICategory) APICategoryListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APICategoryListDTO) Test(org.junit.Test)

Example 2 with APICategoryListDTO

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

the class APICategoryMappingUtil method fromCategoryListToCategoryListDTO.

/**
 * Convert list of API Categories to CategoryListDTO
 *
 * @param categories List of api categories
 * @return CategoryListDTO list containing api category data
 */
public static APICategoryListDTO fromCategoryListToCategoryListDTO(List<APICategory> categories) {
    APICategoryListDTO categoryListDTO = new APICategoryListDTO();
    categoryListDTO.setCount(categories.size());
    categoryListDTO.setList(fromCategoryListToCategoryDTOList(categories));
    return categoryListDTO;
}
Also used : APICategoryListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APICategoryListDTO)

Example 3 with APICategoryListDTO

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

the class ApiCategoriesApiServiceImpl method apiCategoriesGet.

public Response apiCategoriesGet(String xWSO2Tenant, MessageContext messageContext) {
    try {
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        List<APICategory> categoryList = APIUtil.getAllAPICategoriesOfOrganization(organization);
        APICategoryListDTO categoryListDTO = APICategoryMappingUtil.fromCategoryListToCategoryListDTO(categoryList);
        return Response.ok().entity(categoryListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API categories";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APICategory(org.wso2.carbon.apimgt.api.model.APICategory) APICategoryListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APICategoryListDTO)

Example 4 with APICategoryListDTO

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

the class ApiCategoriesApiServiceImpl method apiCategoriesGet.

@Override
public Response apiCategoriesGet(MessageContext messageContext) {
    try {
        APIAdmin apiAdmin = new APIAdminImpl();
        String organization = RestApiUtil.getOrganization(messageContext);
        List<APICategory> categoryList = apiAdmin.getAPICategoriesOfOrganization(organization);
        APICategoryListDTO categoryListDTO = APICategoryMappingUtil.fromCategoryListToCategoryListDTO(categoryList);
        return Response.ok().entity(categoryListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API categories";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) APICategory(org.wso2.carbon.apimgt.api.model.APICategory) APICategoryListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.APICategoryListDTO)

Example 5 with APICategoryListDTO

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

the class APICategoryMappingUtilTestCase method testCategoryDescriptionNull.

@Test
public void testCategoryDescriptionNull() throws Exception {
    APICategory category = new APICategory();
    category.setDescription(null);
    category.setName("test");
    List<APICategory> categories = new ArrayList<APICategory>();
    categories.add(category);
    APICategoryListDTO ListDto = APICategoryMappingUtil.fromCategoryListToCategoryListDTO(categories);
    APICategoryDTO dto = ListDto.getList().get(0);
    Assert.assertEquals("Category is null", "", dto.getDescription());
}
Also used : ArrayList(java.util.ArrayList) APICategoryDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APICategoryDTO) APICategory(org.wso2.carbon.apimgt.api.model.APICategory) APICategoryListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.APICategoryListDTO) Test(org.junit.Test)

Aggregations

APICategory (org.wso2.carbon.apimgt.api.model.APICategory)5 APICategoryListDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APICategoryListDTO)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 APICategoryListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.APICategoryListDTO)2 APICategoryListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APICategoryListDTO)2 APICategoryDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APICategoryDTO)2 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)1 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)1