use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.
the class TestCategoryAction method testAddCategory_1.
public void testAddCategory_1() throws Throwable {
String categoryCode = "cat_temp";
assertNull(this._categoryManager.getCategory(categoryCode));
try {
String result = this.saveNewCategory("admin", categoryCode);
assertEquals(Action.SUCCESS, result);
Category category = this._categoryManager.getCategory(categoryCode);
assertNotNull(category);
assertEquals("Titolo categoria In Italiano", category.getTitles().getProperty("it"));
assertEquals(this._categoryManager.getRoot().getCode(), category.getParentCode());
} catch (Throwable t) {
throw t;
} finally {
this._categoryManager.deleteCategory(categoryCode);
assertNull(this._categoryManager.getCategory(categoryCode));
}
}
use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.
the class TestCategoryAction method testDeleteCategory_1.
public void testDeleteCategory_1() throws Throwable {
String categoryCode = "cat_temp";
assertNull(this._categoryManager.getCategory(categoryCode));
try {
String result = this.saveNewCategory("admin", categoryCode);
assertEquals(Action.SUCCESS, result);
Category category = this._categoryManager.getCategory(categoryCode);
assertNotNull(category);
this.initAction("/do/Category", "trash");
this.addParameter("selectedNode", categoryCode);
result = this.executeAction();
assertEquals(Action.SUCCESS, result);
category = this._categoryManager.getCategory(categoryCode);
assertNotNull(category);
Map<String, Object> references = ((CategoryAction) this.getAction()).getReferences();
assertNull(references);
this.initAction("/do/Category", "delete");
this.addParameter("selectedNode", categoryCode);
result = this.executeAction();
assertEquals(Action.SUCCESS, result);
category = this._categoryManager.getCategory(categoryCode);
assertNull(category);
references = ((CategoryAction) this.getAction()).getReferences();
assertNull(references);
} catch (Throwable t) {
this._categoryManager.deleteCategory(categoryCode);
assertNull(this._categoryManager.getCategory(categoryCode));
throw t;
}
}
use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.
the class TestCategoryAction method testCategoryDetails_1.
public void testCategoryDetails_1() throws Throwable {
String categoryCode = "cat_temp";
assertNull(this._categoryManager.getCategory(categoryCode));
try {
String result = this.executeCategoryDetail("admin", categoryCode);
assertEquals("categoryTree", result);
Collection<String> actionErrors = this.getAction().getActionErrors();
assertEquals(1, actionErrors.size());
result = this.saveNewCategory("admin", categoryCode);
assertEquals(Action.SUCCESS, result);
Category category = this._categoryManager.getCategory(categoryCode);
assertNotNull(category);
result = this.executeCategoryDetail("admin", categoryCode);
assertEquals(Action.SUCCESS, result);
CategoryAction action = (CategoryAction) this.getAction();
assertEquals(categoryCode, action.getCategoryCode());
assertEquals("Titolo categoria In Italiano", action.getTitles().get("it"));
assertEquals("Titolo categoria In Inglese", action.getTitles().get("en"));
assertNull(action.getReferences());
} catch (Throwable t) {
throw t;
} finally {
this._categoryManager.deleteCategory(categoryCode);
assertNull(this._categoryManager.getCategory(categoryCode));
}
}
use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.
the class CategoryService method getCategoryReferences.
@Override
public PagedMetadata<?> getCategoryReferences(String categoryCode, String managerName, RestListRequest restListRequest) {
Category group = this.getCategoryManager().getCategory(categoryCode);
if (null == group) {
logger.warn("no category found with code {}", categoryCode);
throw new ResourceNotFoundException(CategoryValidator.ERRCODE_CATEGORY_NOT_FOUND, "category", categoryCode);
}
CategoryServiceUtilizer<?> utilizer = this.getCategoryServiceUtilizer(managerName);
if (null == utilizer) {
logger.warn("no references found for {}", managerName);
throw new ResourceNotFoundException(CategoryValidator.ERRCODE_CATEGORY_NO_REFERENCES, "reference", managerName);
}
List<?> dtoList = utilizer.getCategoryUtilizer(categoryCode);
List<?> subList = restListRequest.getSublist(dtoList);
SearcherDaoPaginatedResult<?> pagedResult = new SearcherDaoPaginatedResult(dtoList.size(), subList);
PagedMetadata<Object> pagedMetadata = new PagedMetadata<>(restListRequest, pagedResult);
pagedMetadata.setBody((List<Object>) subList);
return pagedMetadata;
}
use of com.agiletec.aps.system.services.category.Category in project entando-core by entando.
the class CategoryService method deleteCategory.
@Override
public void deleteCategory(String categoryCode) {
Category category = this.getCategoryManager().getCategory(categoryCode);
if (null == category) {
throw new ResourceNotFoundException("category", categoryCode);
}
if (category.getChildrenCodes().length > 0) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(category, "category");
bindingResult.reject(CategoryValidator.ERRCODE_CATEGORY_HAS_CHILDREN, new String[] { categoryCode }, "category.cannot.delete.children");
throw new ValidationGenericException(bindingResult);
}
try {
for (CategoryUtilizer categoryUtilizer : this.getCategoryUtilizers()) {
List references = categoryUtilizer.getCategoryUtilizers(categoryCode);
if (null != references && !references.isEmpty()) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(category, "category");
bindingResult.reject(CategoryValidator.ERRCODE_CATEGORY_REFERENCES, new String[] { categoryCode }, "category.cannot.delete.references");
throw new ValidationGenericException(bindingResult);
}
}
this.getCategoryManager().deleteCategory(categoryCode);
} catch (ValidationGenericException e) {
throw e;
} catch (Exception e) {
logger.error("error deleting category " + categoryCode, e);
throw new RestServerError("error deleting category " + categoryCode, e);
}
}
Aggregations