use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class LabelService method validateAddLabelGroup.
protected BeanPropertyBindingResult validateAddLabelGroup(LabelDto labelDto) {
try {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(labelDto, "labelGroup");
String code = labelDto.getKey();
ApsProperties labelGroup = this.getI18nManager().getLabelGroup(code);
if (null != labelGroup) {
bindingResult.reject(LabelValidator.ERRCODE_LABELGROUP_EXISTS, new String[] { code }, "labelGroup.code.already.present");
return bindingResult;
}
String defaultLang = this.getLangManager().getDefaultLang().getCode();
boolean isDefaultLangValid = validateDefaultLang(labelDto, bindingResult, defaultLang);
if (!isDefaultLangValid) {
return bindingResult;
}
List<String> configuredLangs = this.getLangManager().getLangs().stream().map(i -> i.getCode()).collect(Collectors.toList());
labelDto.getTitles().entrySet().forEach(i -> validateLangEntry(i, configuredLangs, defaultLang, bindingResult));
return bindingResult;
} catch (ApsSystemException t) {
logger.error("error in validate add label group with code {}", labelDto.getKey(), t);
throw new RestServerError("error in validate add label group", t);
}
}
use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class LanguageService method getLanguages.
@Override
public PagedMetadata<LanguageDto> getLanguages(RestListRequest requestList) {
try {
List<Lang> langs = this.getLangManager().getAssignableLangs();
Collections.sort(langs, (o1, o2) -> o1.getCode().compareTo(o2.getCode()));
SearcherDaoPaginatedResult<Lang> langsResult = new SearcherDaoPaginatedResult<>(langs.size(), langs);
List<LanguageDto> dtoList = this.getLanguageDtoBuilder().convert(langsResult.getList());
langsResult.setCount(langs.size());
requestList.setPageSize(langs.size());
PagedMetadata<LanguageDto> pagedMetadata = new PagedMetadata<>(requestList, langsResult);
pagedMetadata.setBody(dtoList);
return pagedMetadata;
} catch (Throwable t) {
logger.error("error in search langs", t);
throw new RestServerError("error in search langs", t);
}
}
use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class LanguageService method enableLang.
protected LanguageDto enableLang(String code) {
try {
Lang lang = this.getLangManager().getAssignableLangs().stream().filter(i -> i.getCode().equals(code)).findFirst().orElse(null);
if (null == lang) {
logger.warn("no lang found with code {}", code);
throw new RestRourceNotFoundException(LanguageValidator.ERRCODE_LANGUAGE_DOES_NOT_EXISTS, "language", code);
}
// idempotent
if (null == this.getLangManager().getLang(code)) {
logger.warn("the lang {} is already active", code);
this.getLangManager().addLang(lang.getCode());
}
return this.getLanguageDtoBuilder().convert(lang);
} catch (ApsSystemException ex) {
throw new RestServerError("error enabling lang " + code, ex);
}
}
use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class LanguageService method disableLang.
protected LanguageDto disableLang(String code) {
try {
Lang sysLang = this.getLangManager().getAssignableLangs().stream().filter(i -> i.getCode().equals(code)).findFirst().orElse(null);
if (null == sysLang) {
logger.warn("no lang found with code {}", code);
throw new RestRourceNotFoundException(LanguageValidator.ERRCODE_LANGUAGE_DOES_NOT_EXISTS, "language", code);
}
// idempotent
Lang lang = this.getLangManager().getLang(code);
if (null != this.getLangManager().getLang(code)) {
BeanPropertyBindingResult validations = this.validateDisable(lang);
if (validations.hasErrors()) {
throw new ValidationConflictException(validations);
}
}
this.getLangManager().removeLang(code);
return this.getLanguageDtoBuilder().convert(sysLang);
} catch (ApsSystemException ex) {
throw new RestServerError("error disabling language " + code, ex);
}
}
use of org.entando.entando.aps.system.exception.RestServerError in project entando-core by entando.
the class PageService method updateWidgetConfiguration.
@Override
public WidgetConfigurationDto updateWidgetConfiguration(String pageCode, int frameId, WidgetConfigurationRequest widgetReq) {
try {
IPage page = this.loadPage(pageCode, STATUS_DRAFT);
if (null == page) {
throw new RestRourceNotFoundException(ERRCODE_PAGE_NOT_FOUND, "page", pageCode);
}
if (frameId > page.getWidgets().length) {
throw new RestRourceNotFoundException(ERRCODE_FRAME_INVALID, "frame", String.valueOf(frameId));
}
if (null == this.getWidgetType(widgetReq.getCode())) {
throw new RestRourceNotFoundException(ERRCODE_WIDGET_INVALID, "widget", String.valueOf(widgetReq.getCode()));
}
BeanPropertyBindingResult validation = this.getWidgetValidatorFactory().get(widgetReq.getCode()).validate(widgetReq, page);
if (null != validation && validation.hasErrors()) {
throw new ValidationConflictException(validation);
}
ApsProperties properties = (ApsProperties) this.getWidgetProcessorFactory().get(widgetReq.getCode()).buildConfiguration(widgetReq);
WidgetType widgetType = this.getWidgetType(widgetReq.getCode());
Widget widget = new Widget();
widget.setType(widgetType);
widget.setConfig(properties);
this.getPageManager().joinWidget(pageCode, widget, frameId);
ApsProperties outProperties = this.getWidgetProcessorFactory().get(widgetReq.getCode()).extractConfiguration(widget.getConfig());
return new WidgetConfigurationDto(widget.getType().getCode(), outProperties);
} catch (ApsSystemException e) {
logger.error("Error in update widget configuration {}", pageCode, e);
throw new RestServerError("error in update widget configuration", e);
}
}
Aggregations