use of org.wso2.carbon.apimgt.api.model.APICategory in project carbon-apimgt by wso2.
the class RegistryPersistenceUtilTestCase method testcreateAPIProductArtifactContent.
@Test
public void testcreateAPIProductArtifactContent() throws APIPersistenceException, APIManagementException, RegistryException {
APIProduct product = new APIProduct(new APIProductIdentifier("pubuser", "TestAPIProd", "1.0.0"));
GenericArtifact genericArtifact = new GenericArtifactImpl(new QName("", "TestAPIProd", ""), "application/vnd.wso2-api+xml");
List<APICategory> categories = new ArrayList<APICategory>();
APICategory category = new APICategory();
category.setName("testcategory");
categories.add(category);
product.setApiCategories(categories);
Set<Tier> availableTiers = new HashSet<Tier>();
availableTiers.add(new Tier("Unlimited"));
availableTiers.add(new Tier("Gold"));
product.setAvailableTiers(availableTiers);
GenericArtifact retArtifact = RegistryPersistenceUtil.createAPIProductArtifactContent(genericArtifact, product);
Assert.assertEquals("API name does not match", product.getId().getName(), retArtifact.getAttribute("overview_name"));
Assert.assertEquals("API version does not match", product.getId().getVersion(), retArtifact.getAttribute("overview_version"));
Assert.assertEquals("API provider does not match", product.getId().getProviderName(), retArtifact.getAttribute("overview_provider"));
}
use of org.wso2.carbon.apimgt.api.model.APICategory in project carbon-apimgt by wso2.
the class APICategoryMappingUtil method fromCategoryListToCategoryDTOList.
/**
* Converts api category List to CategoryDTO List.
*
* @param categories List of api categories
* @return CategoryDTO list
*/
private static List<APICategoryDTO> fromCategoryListToCategoryDTOList(List<APICategory> categories) {
List<APICategoryDTO> categoryDTOs = new ArrayList<>();
for (APICategory category : categories) {
APICategoryDTO categoryDTO = new APICategoryDTO();
categoryDTO.setId(category.getId());
categoryDTO.setName(category.getName());
categoryDTO.setDescription(category.getDescription());
categoryDTO.setNumberOfAPIs(category.getNumberOfAPIs());
categoryDTOs.add(categoryDTO);
}
return categoryDTOs;
}
use of org.wso2.carbon.apimgt.api.model.APICategory in project carbon-apimgt by wso2.
the class APICategoryMappingUtil method fromCategoryToCategoryDTO.
/**
* Converts a Category to CategoryDTO
*
* @param category
* @return categoryDTO
*/
public static APICategoryDTO fromCategoryToCategoryDTO(APICategory category) {
APICategoryDTO categoryDTO = new APICategoryDTO();
categoryDTO.setId(category.getId());
categoryDTO.setName(category.getName());
categoryDTO.setDescription(category.getDescription());
return categoryDTO;
}
use of org.wso2.carbon.apimgt.api.model.APICategory in project carbon-apimgt by wso2.
the class APICategoryMappingUtil method fromCategoryDTOToCategory.
/**
* Converts a CategoryDTO to APICategory
*
* @param categoryDTO
* @return APICategoty
*/
public static APICategory fromCategoryDTOToCategory(APICategoryDTO categoryDTO) {
APICategory category = new APICategory();
category.setId(categoryDTO.getId());
category.setName(categoryDTO.getName());
category.setDescription(categoryDTO.getDescription());
return category;
}
use of org.wso2.carbon.apimgt.api.model.APICategory in project carbon-apimgt by wso2.
the class ApiCategoriesApiServiceImpl method apiCategoriesPost.
@Override
public Response apiCategoriesPost(APICategoryDTO body, MessageContext messageContext) {
APICategory apiCategory = null;
try {
APIAdmin apiAdmin = new APIAdminImpl();
String userName = RestApiCommonUtil.getLoggedInUsername();
apiCategory = APICategoryMappingUtil.fromCategoryDTOToCategory(body);
if (!org.apache.commons.lang3.StringUtils.isEmpty(apiCategory.getName())) {
String regExSpecialChars = "!@#$%^&*(),?\"{}[\\]|<>";
String regExSpecialCharsReplaced = regExSpecialChars.replaceAll(".", "\\\\$0");
// include \n,\t, space
Pattern pattern = Pattern.compile("[" + regExSpecialCharsReplaced + "\\s" + "]");
Matcher matcher = pattern.matcher(apiCategory.getName());
if (matcher.find()) {
RestApiUtil.handleBadRequest("Name field contains special characters.", log);
}
if (apiCategory.getName().length() > 255) {
RestApiUtil.handleBadRequest("API Category name is too long.", log);
}
} else {
RestApiUtil.handleBadRequest("API Category name is empty.", log);
}
String organization = RestApiUtil.getOrganization(messageContext);
APICategoryDTO categoryDTO = APICategoryMappingUtil.fromCategoryToCategoryDTO(apiAdmin.addCategory(apiCategory, userName, organization));
URI location = new URI(RestApiConstants.RESOURCE_PATH_CATEGORY + "/" + categoryDTO.getId());
return Response.created(location).entity(categoryDTO).build();
} catch (APIManagementException | URISyntaxException e) {
String errorMessage = "Error while adding new API Category '" + body.getName() + "' - " + e.getMessage();
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
Aggregations