Subversion Repositories SmartDukaan

Rev

Rev 35026 | Rev 35956 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35026 Rev 35198
Line 59... Line 59...
59
        List<AuthUser> authUsers = authRepository.selectAllByManagerAuthId(authId);
59
        List<AuthUser> authUsers = authRepository.selectAllByManagerAuthId(authId);
60
        List<Integer> authIds = authUsers.stream().map(x -> x.getId()).collect(Collectors.toList());
60
        List<Integer> authIds = authUsers.stream().map(x -> x.getId()).collect(Collectors.toList());
61
        LOGGER.info("Auth Id == {}, All Reportees === {}", authId, authIds);
61
        LOGGER.info("Auth Id == {}, All Reportees === {}", authId, authIds);
62
        return authIds;
62
        return authIds;
63
    }
63
    }
64
 
-
 
65
    @Override
64
    @Override
66
    public List<AuthUser> getAllManagers(int authId) {
65
    public List<AuthUser> getAllManagers(int authId) {
67
        AuthUser authUser = authRepository.selectById(authId);
66
        AuthUser authUser = authRepository.selectById(authId);
68
        List<AuthUser> managersHierarchy = new ArrayList<>();
67
        List<AuthUser> managersHierarchy = new ArrayList<>();
-
 
68
 
-
 
69
        // To prevent infinite loops due to circular references
-
 
70
        Set<Integer> visitedIds = new HashSet<>();
-
 
71
        visitedIds.add(authId);
-
 
72
 
69
        while (authUser.getManagerId() != 0) {
73
        while (authUser != null && authUser.getManagerId() != 0) {
-
 
74
            int managerId = authUser.getManagerId();
-
 
75
 
-
 
76
            if (visitedIds.contains(managerId)) {
-
 
77
                LOGGER.warn("Circular reference detected: authId {} -> managerId {}", authUser.getId(), managerId);
-
 
78
                break;
-
 
79
            }
-
 
80
 
70
            AuthUser authUser1 = authRepository.selectById(authUser.getManagerId());
81
            AuthUser manager = authRepository.selectById(managerId);
-
 
82
            if (manager == null) {
-
 
83
                LOGGER.warn("Manager with ID {} not found for user {}", managerId, authUser.getId());
-
 
84
                break;
-
 
85
            }
-
 
86
 
71
            managersHierarchy.add(authUser1);
87
            managersHierarchy.add(manager);
-
 
88
            visitedIds.add(managerId);
-
 
89
 
72
            authUser = authUser1;
90
            authUser = manager;
73
        }
91
        }
-
 
92
 
-
 
93
        LOGGER.info("managersHierarchy {}", managersHierarchy);
74
        return managersHierarchy;
94
        return managersHierarchy;
75
    }
95
    }
76
 
96
 
77
    public List<Integer> getAllReportees(int authId) {
97
    public List<Integer> getAllReportees(int authId) {
78
        return getAllReportees(authId, new HashSet<>());  // call helper with visited set
98
        return getAllReportees(authId, new HashSet<>());  // call helper with visited set