Search in sources :

Example 6 with LabelDto

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) RestResponse(org.entando.entando.web.common.model.RestResponse) LabelDto(org.entando.entando.aps.system.services.label.model.LabelDto) RestAccessControl(org.entando.entando.web.common.annotation.RestAccessControl) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with LabelDto

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);
    }
}
Also used : Logger(org.slf4j.Logger) II18nManager(com.agiletec.aps.system.services.i18n.II18nManager) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) LoggerFactory(org.slf4j.LoggerFactory) RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) ApsProperties(com.agiletec.aps.util.ApsProperties) LabelValidator(org.entando.entando.web.label.LabelValidator) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) ILangManager(com.agiletec.aps.system.services.lang.ILangManager) List(java.util.List) FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) RestListRequest(org.entando.entando.web.common.model.RestListRequest) RestServerError(org.entando.entando.aps.system.exception.RestServerError) Filter(org.entando.entando.web.common.model.Filter) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) Map(java.util.Map) Entry(java.util.Map.Entry) LabelDto(org.entando.entando.aps.system.services.label.model.LabelDto) ValidationGenericException(org.entando.entando.web.common.exceptions.ValidationGenericException) Comparator(java.util.Comparator) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 8 with LabelDto

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;
}
Also used : FieldSearchFilter(com.agiletec.aps.system.common.FieldSearchFilter) Filter(org.entando.entando.web.common.model.Filter) PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) LabelDto(org.entando.entando.aps.system.services.label.model.LabelDto) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

LabelDto (org.entando.entando.aps.system.services.label.model.LabelDto)8 RestAccessControl (org.entando.entando.web.common.annotation.RestAccessControl)4 RestResponse (org.entando.entando.web.common.model.RestResponse)4 ResponseEntity (org.springframework.http.ResponseEntity)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 FieldSearchFilter (com.agiletec.aps.system.common.FieldSearchFilter)3 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)3 ApsProperties (com.agiletec.aps.util.ApsProperties)3 Map (java.util.Map)3 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)3 Filter (org.entando.entando.web.common.model.Filter)3 PagedMetadata (org.entando.entando.web.common.model.PagedMetadata)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)2 II18nManager (com.agiletec.aps.system.services.i18n.II18nManager)2 ILangManager (com.agiletec.aps.system.services.lang.ILangManager)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2