use of com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType in project flowgate by vmware.
the class FacilitySoftwareController method queryFacilitySoftwareConfigByPage.
@RequestMapping(value = "/page/{pageNumber}/pagesize/{pageSize}", method = RequestMethod.GET)
public Page<FacilitySoftwareConfig> queryFacilitySoftwareConfigByPage(@PathVariable("pageNumber") int currentPage, @PathVariable("pageSize") int pageSize, HttpServletRequest request, @RequestParam(required = false) SoftwareType[] softwaretypes) {
WormholeUserDetails user = accessTokenService.getCurrentUser(request);
if (currentPage < FlowgateConstant.defaultPageNumber) {
currentPage = FlowgateConstant.defaultPageNumber;
} else if (pageSize <= 0) {
pageSize = FlowgateConstant.defaultPageSize;
} else if (pageSize > FlowgateConstant.maxPageSize) {
pageSize = FlowgateConstant.maxPageSize;
}
PageRequest pageRequest = PageRequest.of(currentPage - 1, pageSize);
Optional<WormholeUser> currentUserOptional = userRepository.findById(user.getUserId());
WormholeUser currentUser = currentUserOptional.get();
Page<FacilitySoftwareConfig> result = null;
List<String> types = new ArrayList<String>();
if (softwaretypes != null && softwaretypes.length > 0) {
for (SoftwareType type : softwaretypes) {
types.add(type.name());
}
}
if (currentUser.getRoleNames().contains(FlowgateConstant.Role_admin)) {
if (types.isEmpty()) {
result = repository.findAll(pageRequest);
} else {
result = repository.findAllByTypeIn(types, pageRequest);
}
} else {
if (types.isEmpty()) {
result = repository.findALlByUserId(user.getUserId(), pageRequest);
} else {
result = repository.findAllByUserIdAndTypeIn(user.getUserId(), types, pageRequest);
}
}
if (result != null) {
for (FacilitySoftwareConfig facilitySoftwareConfig : result.getContent()) {
facilitySoftwareConfig.setPassword(null);
}
}
return result;
}
Aggregations