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;
}
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;
}
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;
}
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());
}
}
}
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;
}
Aggregations