Search in sources :

Example 6 with CategoryDto

use of org.entando.entando.aps.system.services.category.model.CategoryDto in project entando-core by entando.

the class CategoryService method getCategory.

@Override
public CategoryDto getCategory(String categoryCode) {
    Category category = this.getCategoryManager().getCategory(categoryCode);
    if (null == category) {
        throw new RestRourceNotFoundException(CategoryValidator.ERRCODE_CATEGORY_NOT_FOUND, "category", categoryCode);
    }
    CategoryDto dto = null;
    try {
        dto = this.getDtoBuilder().convert(category);
        for (CategoryUtilizer categoryUtilizer : this.getCategoryUtilizers()) {
            List references = categoryUtilizer.getCategoryUtilizers(categoryCode);
            dto.getReferences().put(((IManager) categoryUtilizer).getName(), (null != references && !references.isEmpty()));
        }
    } catch (Exception e) {
        logger.error("error extracting category " + categoryCode, e);
        throw new RestServerError("error extracting category " + categoryCode, e);
    }
    return dto;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) Category(com.agiletec.aps.system.services.category.Category) CategoryUtilizer(com.agiletec.aps.system.services.category.CategoryUtilizer) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ArrayList(java.util.ArrayList) List(java.util.List) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 7 with CategoryDto

use of org.entando.entando.aps.system.services.category.model.CategoryDto in project entando-core by entando.

the class CategoryService method updateCategory.

@Override
public CategoryDto updateCategory(CategoryDto categoryDto) {
    Category parentCategory = this.getCategoryManager().getCategory(categoryDto.getParentCode());
    if (null == parentCategory) {
        throw new RestRourceNotFoundException(CategoryValidator.ERRCODE_PARENT_CATEGORY_NOT_FOUND, "parent category", categoryDto.getParentCode());
    }
    Category category = this.getCategoryManager().getCategory(categoryDto.getCode());
    if (null == category) {
        throw new RestRourceNotFoundException(CategoryValidator.ERRCODE_CATEGORY_NOT_FOUND, "category", categoryDto.getCode());
    }
    CategoryDto dto = null;
    try {
        category.setParentCode(categoryDto.getParentCode());
        category.getTitles().clear();
        category.getTitles().putAll(categoryDto.getTitles());
        this.getCategoryManager().updateCategory(category);
        dto = this.getDtoBuilder().convert(this.getCategoryManager().getCategory(categoryDto.getCode()));
    } catch (Exception e) {
        logger.error("error updating category " + categoryDto.getCode(), e);
        throw new RestServerError("error updating category " + categoryDto.getCode(), e);
    }
    return dto;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) Category(com.agiletec.aps.system.services.category.Category) RestServerError(org.entando.entando.aps.system.exception.RestServerError) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 8 with CategoryDto

use of org.entando.entando.aps.system.services.category.model.CategoryDto in project entando-core by entando.

the class CategoryController method updateCategory.

@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{categoryCode}", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> updateCategory(@PathVariable String categoryCode, @Valid @RequestBody CategoryDto categoryRequest, BindingResult bindingResult) {
    logger.debug("updating category {} with request {}", categoryCode, categoryRequest);
    // field validations
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    this.getCategoryValidator().validatePutReferences(categoryCode, categoryRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }
    CategoryDto category = this.getCategoryService().updateCategory(categoryRequest);
    Map<String, String> metadata = new HashMap<>();
    return new ResponseEntity<>(new RestResponse(category, new ArrayList<>(), metadata), HttpStatus.OK);
}
Also used : CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) RestResponse(org.entando.entando.web.common.model.RestResponse) ArrayList(java.util.ArrayList) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)8 ArrayList (java.util.ArrayList)6 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)6 Category (com.agiletec.aps.system.services.category.Category)4 HashMap (java.util.HashMap)4 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)4 RestServerError (org.entando.entando.aps.system.exception.RestServerError)4 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)4 RestResponse (org.entando.entando.web.common.model.RestResponse)4 ResponseEntity (org.springframework.http.ResponseEntity)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)2 List (java.util.List)2 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)2 IManager (com.agiletec.aps.system.common.IManager)1 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)1 ICategoryManager (com.agiletec.aps.system.services.category.ICategoryManager)1 Arrays (java.util.Arrays)1 Optional (java.util.Optional)1 DtoBuilder (org.entando.entando.aps.system.services.DtoBuilder)1