use of org.entando.entando.aps.system.services.label.model.LabelDto in project entando-core by entando.
the class LabelController method getLables.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> getLables(RestListRequest requestList) {
logger.debug("loading labels");
this.getLabelValidator().validateRestListRequest(requestList);
PagedMetadata<LabelDto> result = this.getLabelService().getLabelGroups(requestList);
this.getLabelValidator().validateRestListResult(requestList, result);
return new ResponseEntity<>(new RestResponse(result.getBody(), null, result), HttpStatus.OK);
}
use of org.entando.entando.aps.system.services.label.model.LabelDto 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.services.label.model.LabelDto in project entando-core by entando.
the class LabelService method getLabelGroups.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public PagedMetadata<LabelDto> getLabelGroups(RestListRequest restRequest) {
Map<String, ApsProperties> result = this.i18nManager.getLabelGroups();
List<LabelDto> dtoList = this.getDtoBuilder().convert(result);
if (restRequest.getDirection().equals(FieldSearchFilter.DESC_ORDER)) {
dtoList = dtoList.stream().sorted(Comparator.comparing(LabelDto::getKey).reversed()).collect(Collectors.toList());
} else {
dtoList = dtoList.stream().sorted(Comparator.comparing(LabelDto::getKey)).collect(Collectors.toList());
}
if (null != restRequest.getFilters()) {
for (Filter f : restRequest.getFilters()) {
if (f.getAttributeName().equals(LABEL_KEY_FILTER_KEY)) {
dtoList = dtoList.stream().filter(i -> i.getKey().toLowerCase().contains(f.getValue().toLowerCase())).collect(Collectors.toList());
}
if (f.getAttributeName().equals(LABEL_KEY_FILTER_VALUE)) {
dtoList = dtoList.stream().filter(i -> i.getTitles().values().stream().filter(k -> k.contains(f.getValue())).collect(Collectors.toList()).size() > 0).collect(Collectors.toList());
}
}
}
List<?> subList = restRequest.getSublist(dtoList);
SearcherDaoPaginatedResult<LabelDto> resultx = new SearcherDaoPaginatedResult(dtoList.size(), subList);
PagedMetadata<LabelDto> pagedMetadata = new PagedMetadata<>(restRequest, resultx);
pagedMetadata.setBody((List<LabelDto>) subList);
return pagedMetadata;
}
Aggregations