ru.mynewtons.starter.oauth2.service.impl.RoleServiceImpl Maven / Gradle / Ivy
package ru.mynewtons.starter.oauth2.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.mynewtons.starter.oauth2.domain.Role;
import ru.mynewtons.starter.oauth2.exception.EntityNotFoundException;
import ru.mynewtons.starter.oauth2.properties.UsersMessagesProperties;
import ru.mynewtons.starter.oauth2.repository.RoleRepository;
import ru.mynewtons.starter.oauth2.service.RoleService;
import java.util.List;
@Service
@Transactional
public class RoleServiceImpl implements RoleService {
private final RoleRepository roleRepository;
private final UsersMessagesProperties messagesProperties;
@Autowired
public RoleServiceImpl(RoleRepository roleRepository,
UsersMessagesProperties messagesProperties) {
this.roleRepository = roleRepository;
this.messagesProperties = messagesProperties;
}
/**
* {@inheritDoc}
*/
@Transactional(readOnly = true)
@Override
public List findAll() {
return roleRepository.findAll();
}
/**
* {@inheritDoc}
*
* @param id
*/
@Transactional(readOnly = true)
public Role findRoleById(String id) {
Role existingRole = roleRepository.getOne(id);
if (existingRole == null) {
throw new EntityNotFoundException(messagesProperties.getMessage("entity.not.found.by"), Role.class, id);
}
return existingRole;
}
/**
* {@inheritDoc}
*/
@Transactional(readOnly = true)
@Override
public Role findRoleByTitle(String title) {
Role existingRole = roleRepository.findByTitle(title);
if (existingRole == null) {
throw new EntityNotFoundException(messagesProperties.getMessage("entity.not.found.by"), Role.class, "title", title);
}
return existingRole;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy