use of com.agiletec.aps.system.services.category.CategoryUtilizer 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;
}
use of com.agiletec.aps.system.services.category.CategoryUtilizer 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) {
return;
}
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);
}
}
use of com.agiletec.aps.system.services.category.CategoryUtilizer in project entando-core by entando.
the class DataObjectService method getCategoryUtilizer.
@Override
public List getCategoryUtilizer(String categoryCode) {
try {
DataObjectManager entityManager = (DataObjectManager) this.extractEntityManager(this.getManagerName());
List<String> idList = ((CategoryUtilizer) entityManager).getCategoryUtilizers(categoryCode);
return this.buildDtoList(idList, entityManager);
} catch (ApsSystemException ex) {
logger.error("Error loading dataobject references for category {}", categoryCode, ex);
throw new RestServerError("Error loading dataobject references for category", ex);
}
}
use of com.agiletec.aps.system.services.category.CategoryUtilizer in project entando-core by entando.
the class TestCategoryUtilizer method testGetCategoryUtilizers_1.
public void testGetCategoryUtilizers_1() throws Throwable {
String[] names = this.getApplicationContext().getBeanNamesForType(CategoryUtilizer.class);
assertTrue(names.length >= 2);
for (int i = 0; i < names.length; i++) {
CategoryUtilizer service = (CategoryUtilizer) this.getApplicationContext().getBean(names[i]);
List utilizers = service.getCategoryUtilizers("evento");
if (names[i].equals(JacmsSystemConstants.CONTENT_MANAGER)) {
assertTrue(utilizers.size() == 2);
}
}
}
use of com.agiletec.aps.system.services.category.CategoryUtilizer in project entando-core by entando.
the class TestCategoryUtilizer method testGetCategoryUtilizers_2.
public void testGetCategoryUtilizers_2() throws Throwable {
String[] names = this.getApplicationContext().getBeanNamesForType(CategoryUtilizer.class);
assertTrue(names.length >= 2);
for (int i = 0; i < names.length; i++) {
CategoryUtilizer service = (CategoryUtilizer) this.getApplicationContext().getBean(names[i]);
List utilizers = service.getCategoryUtilizers("resCat1");
if (names[i].equals(JacmsSystemConstants.RESOURCE_MANAGER)) {
assertTrue(utilizers.size() == 1);
} else {
assertTrue(utilizers.size() == 0);
}
}
}
Aggregations