Search in sources :

Example 1 with SoftwareType

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;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) SoftwareType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType) WormholeUser(com.vmware.flowgate.common.model.WormholeUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)1 SoftwareType (com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType)1 WormholeUser (com.vmware.flowgate.common.model.WormholeUser)1 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)1 ArrayList (java.util.ArrayList)1 PageRequest (org.springframework.data.domain.PageRequest)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1