<commit_before>package com.imcode.imcms.domain.service.api;

import com.imcode.imcms.domain.dto.RoleDTO;
import com.imcode.imcms.persistence.entity.Role;
import com.imcode.imcms.persistence.repository.RoleRepository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
public class RoleService {

    private final RoleRepository roleRepository;
    private final Function<RoleDTO, Role> roleDtoToRole;
    private final Function<Role, RoleDTO> roleToRoleDTO;

    public RoleService(RoleRepository roleRepository,
                       Function<RoleDTO, Role> roleDtoToRole,
                       Function<Role, RoleDTO> roleToRoleDTO) {

        this.roleRepository = roleRepository;
        this.roleDtoToRole = roleDtoToRole;
        this.roleToRoleDTO = roleToRoleDTO;
    }

    public RoleDTO getById(int id) {
        return roleToRoleDTO.apply(roleRepository.findOne(id));
    }

    public List<RoleDTO> getAll() {
        return roleRepository.findAll().stream()
                .map(roleToRoleDTO)
                .collect(Collectors.toList());
    }

    public RoleDTO save(RoleDTO saveMe) {
        return roleDtoToRole.andThen(roleRepository::save)
                .andThen(roleToRoleDTO)
                .apply(saveMe);
    }

}<commit_msg>IMCMS-255 - Upgrade server side to work with new client: - Added javadoc.<commit_after>package com.imcode.imcms.domain.service.api;

import com.imcode.imcms.domain.dto.RoleDTO;
import com.imcode.imcms.persistence.entity.Role;
import com.imcode.imcms.persistence.repository.RoleRepository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
public class RoleService {

    private final RoleRepository roleRepository;
    private final Function<RoleDTO, Role> roleDtoToRole;
    private final Function<Role, RoleDTO> roleToRoleDTO;

    public RoleService(RoleRepository roleRepository,
                       Function<RoleDTO, Role> roleDtoToRole,
                       Function<Role, RoleDTO> roleToRoleDTO) {

        this.roleRepository = roleRepository;
        this.roleDtoToRole = roleDtoToRole;
        this.roleToRoleDTO = roleToRoleDTO;
    }

    public RoleDTO getById(int id) {
        return roleToRoleDTO.apply(roleRepository.findOne(id));
    }

    public List<RoleDTO> getAll() {
        return roleRepository.findAll().stream()
                .map(roleToRoleDTO)
                .collect(Collectors.toList());
    }

    /**
     * Saves role by it's data holder.
     * <b>Note that {@link RoleDTO#permission} is * omitted while save and in
     * return value.</b>
     *
     * @return saved Role in DTO form.
     */
    public RoleDTO save(RoleDTO saveMe) {
        return roleDtoToRole.andThen(roleRepository::save)
                .andThen(roleToRoleDTO)
                .apply(saveMe);
    }

}
{'fraction_non_alphanumeric': 0.09316353887399464, 'fraction_numerical': 0.0010053619302949062, 'mean_word_length': 2.9019607843137254, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5217578', 'n_tokens_mistral': 888, 'n_tokens_neox': 893, 'n_words': 174}