updated code
This commit is contained in:
@@ -32,23 +32,23 @@ public class DashboardDao {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CompanyRepository companyRepository;
|
private CompanyRepository companyRepository;
|
||||||
|
|
||||||
public SuperAdminWidgetResponseBean getDashboardWidget() {
|
public SuperAdminWidgetResponseBean getDashboardWidget(UserEntity requestedUserEntity) {
|
||||||
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
|
SuperAdminWidgetResponseBean widgetResponseBean = new SuperAdminWidgetResponseBean();
|
||||||
widgetResponseBean.setWidget1(createWidget1());
|
widgetResponseBean.setWidget1(createWidget1(requestedUserEntity));
|
||||||
// List<Object[]> widgetBars = callRepository.findApplicationsPerCall();
|
// List<Object[]> widgetBars = callRepository.findApplicationsPerCall();
|
||||||
// widgetResponseBean.setWidgetBars(widgetBars);
|
// widgetResponseBean.setWidgetBars(widgetBars);
|
||||||
return widgetResponseBean;
|
return widgetResponseBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Widget1 createWidget1() {
|
private Widget1 createWidget1(UserEntity requestedUserEntity) {
|
||||||
Widget1 widget1 = initializeWidget1();
|
Widget1 widget1 = initializeWidget1();
|
||||||
|
|
||||||
setActiveCalls(widget1);
|
setActiveCalls(widget1, requestedUserEntity);
|
||||||
setRegisteredUsers(widget1);
|
setRegisteredUsers(widget1, requestedUserEntity);
|
||||||
setTotalActiveFinancing(widget1);
|
setTotalActiveFinancing(widget1, requestedUserEntity);
|
||||||
setSubmittedApplications(widget1);
|
setSubmittedApplications(widget1, requestedUserEntity);
|
||||||
setDraftApplications(widget1);
|
setDraftApplications(widget1, requestedUserEntity);
|
||||||
setNumberOfCompanies(widget1);
|
setNumberOfCompanies(widget1, requestedUserEntity);
|
||||||
|
|
||||||
return widget1;
|
return widget1;
|
||||||
}
|
}
|
||||||
@@ -59,41 +59,41 @@ public class DashboardDao {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setActiveCalls(Widget1 widget1) {
|
private void setActiveCalls(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||||
Long activeCalls = callRepository.countByStatus(CallStatusEnum.PUBLISH.getValue());
|
Long activeCalls = callRepository.countByStatus(CallStatusEnum.PUBLISH.getValue());
|
||||||
if (activeCalls != null) {
|
if (activeCalls != null) {
|
||||||
widget1.setNumberOfActiveCalls(activeCalls);
|
widget1.setNumberOfActiveCalls(activeCalls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRegisteredUsers(Widget1 widget1) {
|
private void setRegisteredUsers(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||||
Long activeUsers = userRepository.countByStatusAndRoleEntityRoleType(UserStatusEnum.ACTIVE.getValue(),
|
Long activeUsers = userRepository.countByStatusAndRoleEntityRoleTypeAndHubId(UserStatusEnum.ACTIVE.getValue(),
|
||||||
RoleStatusEnum.ROLE_BENEFICIARY.getValue());
|
RoleStatusEnum.ROLE_BENEFICIARY.getValue(), requestedUserEntity.getHub().getId());
|
||||||
if (activeUsers != null) {
|
if (activeUsers != null) {
|
||||||
widget1.setNumberOfResgisteredUsers(activeUsers);
|
widget1.setNumberOfResgisteredUsers(activeUsers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTotalActiveFinancing(Widget1 widget1) {
|
private void setTotalActiveFinancing(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||||
BigDecimal totalActiveFinancing = callRepository.findTotalAmountOfPublishedCalls();
|
BigDecimal totalActiveFinancing = callRepository.findTotalAmountOfPublishedCalls();
|
||||||
widget1.setTotalActiveFinancing(totalActiveFinancing);
|
widget1.setTotalActiveFinancing(totalActiveFinancing);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSubmittedApplications(Widget1 widget1) {
|
private void setSubmittedApplications(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||||
Long submittedApplications = applicationRepository.countSubmittedApplications();
|
Long submittedApplications = applicationRepository.countSubmittedApplications();
|
||||||
if (submittedApplications != null) {
|
if (submittedApplications != null) {
|
||||||
widget1.setNumberOfSubmittedApplications(submittedApplications);
|
widget1.setNumberOfSubmittedApplications(submittedApplications);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDraftApplications(Widget1 widget1) {
|
private void setDraftApplications(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||||
Long draftApplications = applicationRepository.countDraftApplications();
|
Long draftApplications = applicationRepository.countDraftApplications();
|
||||||
if (draftApplications != null) {
|
if (draftApplications != null) {
|
||||||
widget1.setNumberOfDraftApplications(draftApplications);
|
widget1.setNumberOfDraftApplications(draftApplications);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNumberOfCompanies(Widget1 widget1) {
|
private void setNumberOfCompanies(Widget1 widget1, UserEntity requestedUserEntity) {
|
||||||
Long numberOfCompanies = companyRepository.countTotalCompanies();
|
Long numberOfCompanies = companyRepository.countTotalCompanies();
|
||||||
if (numberOfCompanies != null) {
|
if (numberOfCompanies != null) {
|
||||||
widget1.setNumberOfCompany(numberOfCompanies);
|
widget1.setNumberOfCompany(numberOfCompanies);
|
||||||
|
|||||||
@@ -400,15 +400,15 @@ public class UserDao {
|
|||||||
return authService.validateNewUserToken(token);
|
return authService.validateNewUserToken(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UserResponseBean> getAllUsers(Long roleId) {
|
public List<UserResponseBean> getAllUsers(UserEntity user, Long roleId) {
|
||||||
List<UserEntity> users;
|
List<UserEntity> users;
|
||||||
if (roleId != null) {
|
if (roleId != null) {
|
||||||
log.info("Fetching users by role ID: {}", roleId);
|
log.info("Fetching users by role ID: {}", roleId);
|
||||||
RoleEntity roleEntity=roleService.validateRole(roleId);
|
RoleEntity roleEntity=roleService.validateRole(roleId);
|
||||||
users = userRepository.findByRoleEntityId(roleEntity.getId());
|
users = userRepository.findByRoleEntityIdAndHubId(roleEntity.getId(), user.getHub().getId());
|
||||||
} else {
|
} else {
|
||||||
log.info("Fetching all users");
|
log.info("Fetching all users");
|
||||||
users = userRepository.findAll();
|
users = userRepository.findByHubId(user.getHub().getId());
|
||||||
}
|
}
|
||||||
List<UserResponseBean> userResponseBeans = users.stream()
|
List<UserResponseBean> userResponseBeans = users.stream()
|
||||||
.map(this::convertUserEntityToUserResponse)
|
.map(this::convertUserEntityToUserResponse)
|
||||||
|
|||||||
@@ -23,9 +23,14 @@ public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
|||||||
UserEntity findByBeneficiaryId(Long beneficiaryId);
|
UserEntity findByBeneficiaryId(Long beneficiaryId);
|
||||||
|
|
||||||
Long countByStatusAndRoleEntityRoleType(String status, String roleName);
|
Long countByStatusAndRoleEntityRoleType(String status, String roleName);
|
||||||
List<UserEntity> findByRoleEntityId(Long roleId);
|
|
||||||
|
|
||||||
Optional<UserEntity> findByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubId);
|
Optional<UserEntity> findByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubId);
|
||||||
|
|
||||||
boolean existsByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid);
|
boolean existsByEmailIgnoreCaseAndHubUniqueUuid(String email, String hubUuid);
|
||||||
|
|
||||||
|
List<UserEntity> findByRoleEntityIdAndHubId(Long roleId, Long hubId);
|
||||||
|
|
||||||
|
List<UserEntity> findByHubId(Long hubId);
|
||||||
|
|
||||||
|
Long countByStatusAndRoleEntityRoleTypeAndHubId(String status, String roleName, Long hubId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,14 +39,12 @@ public interface UserService {
|
|||||||
|
|
||||||
UserResponseBean getValidUser(HttpServletRequest request);
|
UserResponseBean getValidUser(HttpServletRequest request);
|
||||||
|
|
||||||
List<UserResponseBean> getUserByHubId(String hubId);
|
|
||||||
|
|
||||||
JWTToken validateExistingUserToken(HttpServletRequest request, String token);
|
JWTToken validateExistingUserToken(HttpServletRequest request, String token);
|
||||||
|
|
||||||
UserSamlResponse validateNewUserToken(HttpServletRequest request, String token);
|
UserSamlResponse validateNewUserToken(HttpServletRequest request, String token);
|
||||||
UserEntity getUserByBeneficiaryId(Long beneficiaryId);
|
UserEntity getUserByBeneficiaryId(Long beneficiaryId);
|
||||||
|
|
||||||
public UserEntity getUserEntityById(Long userId);
|
public UserEntity getUserEntityById(Long userId);
|
||||||
List<UserResponseBean> getAllUsers(Long roleId);
|
List<UserResponseBean> getAllUsers(HttpServletRequest request, Long roleId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ public class DashboardServiceImpl implements DashboardService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SuperAdminWidgetResponseBean getDashboardWidgetForSuperAdmin(HttpServletRequest request) {
|
public SuperAdminWidgetResponseBean getDashboardWidgetForSuperAdmin(HttpServletRequest request) {
|
||||||
return dashboardDao.getDashboardWidget();
|
UserEntity userEntity=validator.validateUser(request);
|
||||||
|
return dashboardDao.getDashboardWidget(userEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -97,12 +97,6 @@ public class UserServiceImpl implements UserService {
|
|||||||
return userDao.getUserById(user.getId());
|
return userDao.getUserById(user.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public List<UserResponseBean> getUserByHubId(String hubId) {
|
|
||||||
return userDao.getUserByHubId(hubId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public JWTToken validateExistingUserToken(HttpServletRequest request, String token) {
|
public JWTToken validateExistingUserToken(HttpServletRequest request, String token) {
|
||||||
@@ -123,8 +117,8 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public List<UserResponseBean> getAllUsers(Long roleId) {
|
public List<UserResponseBean> getAllUsers(HttpServletRequest request, Long roleId) {
|
||||||
// Calling DAO Function
|
UserEntity user=validator.validateUser(request);
|
||||||
return userDao.getAllUsers(roleId);
|
return userDao.getAllUsers(user, roleId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,21 +195,6 @@ public interface UserApi {
|
|||||||
ResponseEntity<Response<UserResponseBean>> getValidUser(HttpServletRequest request);
|
ResponseEntity<Response<UserResponseBean>> getValidUser(HttpServletRequest request);
|
||||||
|
|
||||||
|
|
||||||
@Operation(summary = "Api to get user by hubId",
|
|
||||||
responses = {
|
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
|
||||||
@ApiResponse(responseCode = "404", description = "User not found", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
|
||||||
@ExampleObject(value = ErrorConstants.NOTFOUND_ERROR_EXAMPLE)})),
|
|
||||||
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, examples = {
|
|
||||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))
|
|
||||||
})
|
|
||||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
|
||||||
@RequestMapping(value = "/hub/{hubId}",
|
|
||||||
produces = {"application/json"},
|
|
||||||
method = RequestMethod.GET)
|
|
||||||
ResponseEntity<Response<List<UserResponseBean>>> getUserByHubId(
|
|
||||||
@Parameter(description = "The hubId", required = true) @PathVariable("hubId") String hubId);
|
|
||||||
|
|
||||||
@Operation(summary = "Api to validate existing user from saml token",
|
@Operation(summary = "Api to validate existing user from saml token",
|
||||||
responses = {
|
responses = {
|
||||||
@ApiResponse(responseCode = "200", description = "OK"),
|
@ApiResponse(responseCode = "200", description = "OK"),
|
||||||
@@ -250,7 +235,7 @@ public interface UserApi {
|
|||||||
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
|
@ExampleObject(value = ErrorConstants.BADREQUEST_ERROR_EXAMPLE)}))})
|
||||||
@RequestMapping(value = "", produces = {"application/json"}, method = RequestMethod.GET)
|
@RequestMapping(value = "", produces = {"application/json"}, method = RequestMethod.GET)
|
||||||
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
@PreAuthorize("hasRole('ROLE_SUPER_ADMIN')")
|
||||||
ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(
|
ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(HttpServletRequest request,
|
||||||
@Parameter( required = false)@RequestParam(value ="roleId", required = false) Long roleId);
|
@Parameter( required = false)@RequestParam(value ="roleId", required = false) Long roleId);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -128,14 +128,6 @@ public class UserApiController implements UserApi {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ResponseEntity<Response<List<UserResponseBean>>> getUserByHubId(String hubId) {
|
|
||||||
log.info("Get User by Hub ID - Hub ID: {}", hubId);
|
|
||||||
List<UserResponseBean> user = userService.getUserByHubId(hubId);
|
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
|
||||||
.body(new Response<>(user, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USER_SUCCESS_MSG)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<JWTToken>> validateExistingUserToken(HttpServletRequest request, String token) {
|
public ResponseEntity<Response<JWTToken>> validateExistingUserToken(HttpServletRequest request, String token) {
|
||||||
log.info("User login attempt via spid token");
|
log.info("User login attempt via spid token");
|
||||||
@@ -150,10 +142,10 @@ public class UserApiController implements UserApi {
|
|||||||
return ResponseEntity.ok(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.TOKEN_VALIDATE_SUCCESS_MSE)));
|
return ResponseEntity.ok(new Response<>(data, Status.SUCCESS, Translator.toLocale(GepafinConstant.TOKEN_VALIDATE_SUCCESS_MSE)));
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(
|
public ResponseEntity<Response<List<UserResponseBean>>> getAllUsers(HttpServletRequest request,
|
||||||
Long roleId) {
|
Long roleId) {
|
||||||
log.info("Get all Users by Role ID - Role ID: {}", roleId);
|
log.info("Get all Users by Role ID - Role ID: {}", roleId);
|
||||||
List<UserResponseBean> users = userService.getAllUsers(roleId);
|
List<UserResponseBean> users = userService.getAllUsers(request, roleId);
|
||||||
return ResponseEntity.status(HttpStatus.OK)
|
return ResponseEntity.status(HttpStatus.OK)
|
||||||
.body(new Response<>(users, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USERS_SUCCESS_MSG)));
|
.body(new Response<>(users, Status.SUCCESS, Translator.toLocale(GepafinConstant.GET_USERS_SUCCESS_MSG)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user