use of com.agiletec.aps.system.services.lang.Lang in project entando-core by entando.
the class TestDataObjectViewerHelper method init.
private void init() throws Exception {
try {
_requestContext = this.getRequestContext();
Lang lang = new Lang();
lang.setCode("it");
lang.setDescr("italiano");
_requestContext.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG, lang);
Widget widget = new Widget();
IWidgetTypeManager showletTypeMan = (IWidgetTypeManager) this.getService(SystemConstants.WIDGET_TYPE_MANAGER);
WidgetType showletType = showletTypeMan.getWidgetType("content_viewer");
widget.setType(showletType);
widget.setConfig(new ApsProperties());
_requestContext.addExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET, widget);
this._helper = (IDataObjectViewerHelper) this.getApplicationContext().getBean("DataObjectViewerHelper");
} catch (Throwable t) {
throw new Exception(t);
}
}
use of com.agiletec.aps.system.services.lang.Lang in project entando-core by entando.
the class ApiI18nLabelInterface method checkLabels.
protected void checkLabels(JAXBI18nLabel jaxbI18nLabel) throws ApiException {
try {
String key = jaxbI18nLabel.getKey();
if (null == key || key.trim().length() == 0) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label key required", Response.Status.CONFLICT);
}
ApsProperties labels = jaxbI18nLabel.extractLabels();
if (null == labels || labels.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label list can't be empty", Response.Status.CONFLICT);
}
Lang defaultLang = this.getLangManager().getDefaultLang();
Object defaultLangValue = labels.get(defaultLang.getCode());
if (null == defaultLangValue || defaultLangValue.toString().trim().length() == 0) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label list must contain a label for the default language '" + defaultLang.getCode() + "'", Response.Status.CONFLICT);
}
Iterator<Object> labelCodeIter = labels.keySet().iterator();
while (labelCodeIter.hasNext()) {
Object langCode = labelCodeIter.next();
Object value = labels.get(langCode);
if (null == value || value.toString().trim().length() == 0) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label for the language '" + langCode + "' is empty", Response.Status.CONFLICT);
}
}
} catch (ApiException ae) {
throw new ApiException("Error in method checkLabels ", ae);
}
}
use of com.agiletec.aps.system.services.lang.Lang 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 com.agiletec.aps.system.services.lang.Lang 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 com.agiletec.aps.system.services.lang.Lang 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);
}
}
Aggregations