Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bg.codexio.erp.gateway.services;
- import bg.codexio.erp.gateway.entities.Permission;
- import bg.codexio.erp.gateway.entities.Route;
- import bg.codexio.erp.gateway.models.binding.PermissionBindingModel;
- import bg.codexio.erp.gateway.repositories.PermissionRepository;
- import bg.codexio.erp.gateway.repositories.RouteRepository;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.HashSet;
- import java.util.List;
- /**
- * @author M.Damesova on 24/07/19
- */
- @Service
- public class PermissionService {
- private final PermissionRepository permissionRepository;
- private final RouteRepository routeRepository;
- public PermissionService(
- PermissionRepository permissionRepository,
- RouteRepository routeRepository) {
- this.permissionRepository = permissionRepository;
- this.routeRepository = routeRepository;
- }
- public void save(List<PermissionBindingModel> permissionBindingModels) {
- permissionBindingModels.forEach((permissionBindingModel -> {
- var permission = new Permission();
- permission.setName(permissionBindingModel.getName());
- var routes = new HashSet<Route>();
- permissionBindingModel.getRoutes().forEach((routeBindingModel -> {
- var route = new Route();
- route.setMethodType(routeBindingModel.getMethodType());
- route.setPath((routeBindingModel.getPath()));
- routes.add(route);
- }));
- permission.setRoutes(routes);
- this.routeRepository.saveAll(routes);
- this.permissionRepository.save(permission);
- }));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement