use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class WidgetService method updateWidget.
@Override
public WidgetDto updateWidget(String widgetCode, WidgetRequest widgetRequest) {
WidgetType type = this.getWidgetManager().getWidgetType(widgetCode);
if (type == null) {
throw new RestRourceNotFoundException(WidgetValidator.ERRCODE_WIDGET_DOES_NOT_EXISTS, "widget", widgetCode);
} else if (null == this.getGroupManager().getGroup(widgetRequest.getGroup())) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(type, "widget");
bindingResult.reject(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID, new String[] { widgetRequest.getGroup() }, "widgettype.group.invalid");
throw new ValidationGenericException(bindingResult);
}
this.processWidgetType(type, widgetRequest);
WidgetDto widgetDto = dtoBuilder.convert(type);
try {
this.getWidgetManager().updateWidgetType(widgetCode, type.getTitles(), type.getConfig(), type.getMainGroup());
if (!StringUtils.isEmpty(widgetCode)) {
GuiFragment guiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetCode);
if (null == guiFragment) {
this.createAndAddFragment(type, widgetRequest);
} else {
guiFragment.setGui(widgetRequest.getCustomUi());
this.getGuiFragmentManager().updateGuiFragment(guiFragment);
}
}
this.addFragments(widgetDto);
} catch (Throwable e) {
logger.error("failed to update widget type", e);
throw new RestServerError("Failed to update widget", e);
}
return widgetDto;
}
use of org.entando.entando.aps.system.exception.RestServerError 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 RestRourceNotFoundException(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 org.entando.entando.aps.system.exception.RestServerError 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 org.entando.entando.aps.system.exception.RestServerError 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 org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class DatabaseService method getShortDumpReportDtos.
@Override
public PagedMetadata<ShortDumpReportDto> getShortDumpReportDtos(RestListRequest requestList) {
PagedMetadata<ShortDumpReportDto> result = null;
List<ShortDumpReportDto> dtos = new ArrayList<>();
try {
List<DataSourceDumpReport> reports = this.getDatabaseManager().getBackupReports();
if (null != reports) {
reports.stream().forEach(report -> dtos.add(new ShortDumpReportDto(report)));
}
List<ShortDumpReportDto> sublist = requestList.getSublist(dtos);
int size = (null != reports) ? reports.size() : 0;
SearcherDaoPaginatedResult searchResult = new SearcherDaoPaginatedResult(size, sublist);
result = new PagedMetadata<>(requestList, searchResult);
result.setBody(sublist);
} catch (Throwable t) {
logger.error("error extracting database reports", t);
throw new RestServerError("error extracting database reports", t);
}
return result;
}
Aggregations