Search in sources :

Example 36 with Category

use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.

the class CategoryService method getTree.

@Override
public List<CategoryDto> getTree(String parentCode) {
    List<CategoryDto> res = new ArrayList<>();
    Category parent = this.getCategoryManager().getCategory(parentCode);
    if (null == parent) {
        throw new ResourceNotFoundException(CategoryValidator.ERRCODE_PARENT_CATEGORY_NOT_FOUND, "category", parentCode);
    }
    Optional.ofNullable(parent.getChildrenCodes()).ifPresent(children -> Arrays.asList(children).forEach(childCode -> {
        Category child = this.getCategoryManager().getCategory(childCode);
        CategoryDto childDto = this.getDtoBuilder().convert(child);
        childDto.setChildren(Arrays.asList(child.getChildrenCodes()));
        res.add(childDto);
    }));
    return res;
}
Also used : CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) LoggerFactory(org.slf4j.LoggerFactory) CategoryValidator(org.entando.entando.web.category.validator.CategoryValidator) Autowired(org.springframework.beans.factory.annotation.Autowired) DtoBuilder(org.entando.entando.aps.system.services.DtoBuilder) ArrayList(java.util.ArrayList) List(java.util.List) RestListRequest(org.entando.entando.web.common.model.RestListRequest) RestServerError(org.entando.entando.aps.system.exception.RestServerError) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) CategoryUtilizer(com.agiletec.aps.system.services.category.CategoryUtilizer) IManager(com.agiletec.aps.system.common.IManager) Optional(java.util.Optional) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) Category(com.agiletec.aps.system.services.category.Category) ICategoryManager(com.agiletec.aps.system.services.category.ICategoryManager) IDtoBuilder(org.entando.entando.aps.system.services.IDtoBuilder) Category(com.agiletec.aps.system.services.category.Category) ArrayList(java.util.ArrayList) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException)

Example 37 with Category

use of com.agiletec.aps.system.services.category.Category 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 ResourceNotFoundException(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 : 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) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 38 with Category

use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.

the class CategoryService method addCategory.

@Override
public CategoryDto addCategory(CategoryDto categoryDto) {
    Category parentCategory = this.getCategoryManager().getCategory(categoryDto.getParentCode());
    if (null == parentCategory) {
        throw new ResourceNotFoundException(CategoryValidator.ERRCODE_PARENT_CATEGORY_NOT_FOUND, "parent category", categoryDto.getParentCode());
    }
    Category category = this.getCategoryManager().getCategory(categoryDto.getCode());
    if (null != category) {
        BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(category, "category");
        bindingResult.reject(CategoryValidator.ERRCODE_CATEGORY_ALREADY_EXISTS, new String[] { category.getCode() }, "category.exists");
        throw new ValidationGenericException(bindingResult);
    }
    CategoryDto dto = null;
    try {
        Category categoryToAdd = new Category();
        categoryToAdd.setCode(categoryDto.getCode());
        categoryToAdd.setParentCode(categoryDto.getParentCode());
        categoryToAdd.getTitles().putAll(categoryDto.getTitles());
        this.getCategoryManager().addCategory(categoryToAdd);
        dto = this.getDtoBuilder().convert(this.getCategoryManager().getCategory(categoryDto.getCode()));
    } catch (Exception e) {
        logger.error("error adding category " + categoryDto.getCode(), e);
        throw new RestServerError("error adding category " + categoryDto.getCode(), e);
    }
    return dto;
}
Also used : CategoryDto(org.entando.entando.aps.system.services.category.model.CategoryDto) Category(com.agiletec.aps.system.services.category.Category) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) ResourceNotFoundException(org.entando.entando.aps.system.exception.ResourceNotFoundException) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException)

Example 39 with Category

use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.

the class DataObjectDAO method addCategoryRelationsRecord.

private void addCategoryRelationsRecord(DataObject dataobject, boolean isPublicRelations, PreparedStatement stat) throws ApsSystemException {
    if (dataobject.getCategories().size() > 0) {
        try {
            Set<String> codes = new HashSet<String>();
            Iterator<Category> categoryIter = dataobject.getCategories().iterator();
            while (categoryIter.hasNext()) {
                Category category = (Category) categoryIter.next();
                this.addCategoryCode(category, codes);
            }
            Iterator<String> codeIter = codes.iterator();
            while (codeIter.hasNext()) {
                String code = codeIter.next();
                int i = 1;
                stat.setString(i++, dataobject.getId());
                /*
					if (isPublicRelations) {
						stat.setString(i++, null);
						stat.setString(i++, null);
						stat.setBigDecimal(i++, null);
					}
                     */
                stat.setString(i++, code);
                if (isPublicRelations) {
                    stat.setString(i++, null);
                }
                stat.addBatch();
                stat.clearParameters();
            }
        } catch (SQLException e) {
            _logger.error("Error saving dataobject relation record for dataobject {}", dataobject.getId(), e.getNextException());
            throw new RuntimeException("Error saving dataobject relation record for dataobject " + dataobject.getId(), e.getNextException());
        }
    }
}
Also used : Category(com.agiletec.aps.system.services.category.Category) SQLException(java.sql.SQLException) HashSet(java.util.HashSet)

Example 40 with Category

use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.

the class CategoryAction method save.

public String save() {
    try {
        if (this.getStrutsAction() == ApsAdminSystemConstants.EDIT) {
            Category category = this.getCategory(this.getCategoryCode());
            category.setTitles(this.getTitles());
            this.getCategoryManager().updateCategory(category);
            _logger.debug("Updated category {}", category.getCode());
        } else if (this.getStrutsAction() == ApsAdminSystemConstants.ADD) {
            String parentCategoryCode = this.getParentCategoryCode();
            Category category = this.getHelper().buildNewCategory(this.getCategoryCode(), parentCategoryCode, this.getTitles());
            this.getCategoryManager().addCategory(category);
            _logger.debug("Added new category {}", this.getCategoryCode());
        } else {
            _logger.error("Select a position");
            this.addFieldError("categoryCode", this.getText("error.category.noParentSelected"));
            return FAILURE;
        }
    } catch (Exception e) {
        _logger.error("error in save", e);
        return FAILURE;
    }
    return SUCCESS;
}
Also used : Category(com.agiletec.aps.system.services.category.Category)

Aggregations

Category (com.agiletec.aps.system.services.category.Category)91 ArrayList (java.util.ArrayList)23 ITreeNode (com.agiletec.aps.system.common.tree.ITreeNode)9 ResourceNotFoundException (org.entando.entando.aps.system.exception.ResourceNotFoundException)7 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)6 TextAttribute (com.agiletec.aps.system.common.entity.model.attribute.TextAttribute)6 List (java.util.List)6 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)6 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)5 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)5 RestServerError (org.entando.entando.aps.system.exception.RestServerError)5 ICategoryManager (com.agiletec.aps.system.services.category.ICategoryManager)4 Lang (com.agiletec.aps.system.services.lang.Lang)4 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)4 CategoryDto (org.entando.entando.aps.system.services.category.model.CategoryDto)4 IDataObjectSearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.IDataObjectSearchEngineManager)4 SearchEngineManager (org.entando.entando.aps.system.services.dataobjectsearchengine.SearchEngineManager)4 Cache (org.springframework.cache.Cache)4 CategoryUtilizer (com.agiletec.aps.system.services.category.CategoryUtilizer)3 HashSet (java.util.HashSet)3