/**
   * 生成应用明细告警展示信息
   *
   * @param applicationId 所属应用ID
   * @return 告警展示信息
   */
  public ApplicationDetailAlarmViewModel generateAlarmViewModel(String applicationId) {
    Date startDate = DateUtil.getTodayBeginDate();
    Date endDate = new Date();

    Application application = applicationRepository.findApplicationbyId(applicationId);
    int interval = application.getInterval().intValue();
    ApplicationDetailAlarmViewModel applicationDetailAlarmViewModel =
        new ApplicationDetailAlarmViewModel();
    // 获得健康度
    SeverityLevel severityLevel = healthStaService.healthStaForCurrent(applicationId, interval);

    applicationDetailAlarmViewModel.setSeverityLevel(severityLevel);
    int criticalCount = alarmRepository.countCriticalByMonitorId(applicationId, startDate, endDate);

    Pageable pageable = new PageRequest(0, 10, Sort.Direction.DESC, "create_time");
    Page<Alarm> alarmPage =
        alarmRepository.selectCriticalAlarmsByMonitorId(
            pageable, applicationId, startDate, endDate);
    Iterator<Alarm> alarmIterator = alarmPage.iterator();
    while (alarmIterator.hasNext()) {
      applicationDetailAlarmViewModel.addAlarmInfo(alarmIterator.next().getMessage());
    }

    applicationDetailAlarmViewModel.setCriticalCount(criticalCount);
    return applicationDetailAlarmViewModel;
  }
  @WithMockUser(username = "******", password = "******", roles = "ADMIN")
  @Test
  public void testGetEventsForUser() {
    User user1 = userService.read(1L);
    User user2 = userService.read(2L);
    User user3 = userService.read(3L);

    Page<ProjectEvent> events1 =
        projectEventService.getEventsForUser(user1, new PageRequest(0, 10));
    Page<ProjectEvent> events2 =
        projectEventService.getEventsForUser(user2, new PageRequest(0, 10));
    Page<ProjectEvent> events3 =
        projectEventService.getEventsForUser(user3, new PageRequest(0, 10));

    assertEquals(1L, events1.getTotalElements());
    assertEquals(0L, events2.getTotalElements());
    assertEquals(1L, events3.getTotalElements());

    ProjectEvent event1 = events1.iterator().next();
    ProjectEvent event3 = events3.iterator().next();
    assertEquals(event1, event3);
  }
  @RequestMapping(value = "/listgrid", method = RequestMethod.GET, produces = "application/json")
  @ResponseBody
  public HotelGrid listGrid(
      @RequestParam(value = "page", required = false) Integer page,
      @RequestParam(value = "rows", required = false) Integer rows,
      @RequestParam(value = "sidx", required = false) String sortBy,
      @RequestParam(value = "sord", required = false)
          String order) { // , @PathVariable("str") String str

    logger.info("Listing tours for grid with page:{}, rows: {}", page, rows);
    logger.info("Listing tours for grid woth sort:{}, order: {}", sortBy, order);

    // Process order by
    Sort sort = null;
    String orderBy = sortBy;
    if (orderBy != null && orderBy.equals("phone")) orderBy = "phone";

    if (orderBy != null && order != null) {
      if (order.equals("desc")) {
        sort = new Sort(Sort.Direction.DESC, orderBy);
      } else sort = new Sort(Sort.Direction.ASC, orderBy);
    }

    // Construcs page request for current page
    // Note: page number for Spring Data JPA starts with 0, While jqGrid Starts with 1
    // PageRequest pageRequest = null;
    MyPageRequest myPageRequest = null;

    if (sort != null) {
      // pageRequest = new PageRequest(page-1,rows,sort);
      myPageRequest = new MyPageRequest(page - 1, rows, searchTerm, sort);
    } else {
      // pageRequest = new PageRequest(page-1,rows);
      myPageRequest = new MyPageRequest(page - 1, rows, searchTerm);
    }

    // Page<Hotel> hotelPage = hotelService.findAllByPage(pageRequest);
    Page<Hotel> hotelPage = hotelService.search(myPageRequest);

    // Construct the grid data that will return as JSON data
    HotelGrid hotelGrid = new HotelGrid();

    hotelGrid.setCurrentPage(hotelPage.getNumber() + 1);
    hotelGrid.setTotalPages(hotelPage.getTotalPages());
    hotelGrid.setTotalRecords(hotelPage.getTotalElements());

    hotelGrid.setHotelData(Lists.newArrayList(hotelPage.iterator()));

    return hotelGrid;
  }
 @RequestMapping(value = "/admin/taxRates", method = RequestMethod.GET)
 public String taxRates(
     @RequestParam(value = "page", defaultValue = FIRST_PAGE) int page, Model model) {
   int menuCategory = AdminMenuCategory.LOCATION_TAXES.ordinal();
   model.addAttribute("menuCategory", menuCategory);
   Pageable pageRequest = new PageRequest(page, PAGE_SIZE, Sort.Direction.ASC, "priority");
   Page<TaxRate> taxRates = taxRateService.findAll(pageRequest);
   model.addAttribute("taxRates", taxRates);
   TaxRate thisTaxRate = null;
   if (taxRates.getContent().size() > 0) {
     thisTaxRate = taxRates.iterator().next();
   }
   model.addAttribute("thisTaxRate", thisTaxRate);
   return "admin/taxes/taxRates";
 }
  @Override
  public MonthIndicator getLastMonthIndicator() {
    Page<MonthIndicator> page =
        repository.findAll(new PageRequest(0, 1, Sort.Direction.DESC, "dateTime"));

    MonthIndicator monthIndicator;
    if (Objects.nonNull(page)) {
      monthIndicator = page.iterator().next();

      log.debug("Found Last Month Indicator: {}", monthIndicator);
      return monthIndicator;
    }

    log.error("Could not found Last Month Indicator in DB");

    return null;
  }
Beispiel #6
0
  // Построничное разбиение информации в гриде
  @ResponseBody
  @RequestMapping(value = "/listgrid", method = RequestMethod.GET, produces = "application/json")
  public BanksGrid listGrid(
      @RequestParam(value = "page", required = false) Integer page,
      @RequestParam(value = "rows", required = false) Integer rows,
      @RequestParam(value = "sidx", required = false) String sortBy,
      @RequestParam(value = "sord", required = false) String order) {

    logger.info("Listing banks for grid with page: {}, rows: {}", page, rows);
    logger.info("Listing banks for grid with sort: {}, order: {}", sortBy, order);

    // Process order by
    Sort sort = null;
    String orderBy = sortBy;
    //        if (orderBy != null && orderBy.equals("birthDateString"))
    //            orderBy = "birthDate";

    if (orderBy != null && order != null) {
      if (order.equals("desc")) {
        sort = new Sort(Sort.Direction.DESC, orderBy);
      } else sort = new Sort(Sort.Direction.ASC, orderBy);
    }

    // Constructs page request for current page
    // Note: page number for Spring Data JPA starts with 0, while jqGrid starts with 1
    PageRequest pageRequest = null;

    if (sort != null) {
      pageRequest = new PageRequest(page - 1, rows, sort);
    } else {
      pageRequest = new PageRequest(page - 1, rows);
    }

    Page<Banks> banksPage = banksService.findAllByPage(pageRequest);

    // Construct the grid data that will return as JSON data
    BanksGrid banksGrid = new BanksGrid();

    banksGrid.setCurrentPage(banksPage.getNumber() + 1);
    banksGrid.setTotalPages(banksPage.getTotalPages());
    banksGrid.setTotalRecords(banksPage.getTotalElements());

    banksGrid.setBanksData(Lists.newArrayList(banksPage.iterator()));

    return banksGrid;
  }
  @WithMockUser(username = "******", password = "******", roles = "ADMIN")
  @Test
  public void testGetEventsForProject() {
    Project project1 = projectService.read(1L);
    Project project3 = projectService.read(3L);

    Page<ProjectEvent> eventsForProject1 =
        projectEventService.getEventsForProject(project1, new PageRequest(0, 10));
    Page<ProjectEvent> eventsForProject2 =
        projectEventService.getEventsForProject(project3, new PageRequest(0, 10));

    assertEquals(0L, eventsForProject1.getTotalElements());
    assertEquals(1L, eventsForProject2.getTotalElements());

    ProjectEvent event2 = eventsForProject2.iterator().next();

    assertEquals(project3, event2.getProject());
  }
  @WithMockUser(username = "******", password = "******", roles = "ADMIN")
  @Test
  public void testUpdateProjectUser() throws ProjectWithoutOwnerException {
    Project project = projectService.read(1L);
    User user = userService.read(1L);

    projectService.updateUserProjectRole(project, user, ProjectRole.PROJECT_USER);

    Page<ProjectEvent> eventsForProject =
        projectEventService.getEventsForProject(project, new PageRequest(0, 10));

    assertEquals(1, eventsForProject.getTotalElements());
    ProjectEvent event = eventsForProject.iterator().next();

    assertTrue(event instanceof UserRoleSetProjectEvent);
    UserRoleSetProjectEvent userEvent = (UserRoleSetProjectEvent) event;
    assertEquals(project, userEvent.getProject());
    assertEquals(user, userEvent.getUser());
  }
  @RequestMapping(
      value = "/questionslist",
      method = RequestMethod.GET,
      produces = "application/json")
  @ResponseBody
  public QuestionGrid listQuestion(
      @RequestParam(value = "page", required = false) Integer page,
      @RequestParam(value = "rows", required = false) Integer rows,
      @RequestParam(value = "sidx", required = false) String sortBy,
      @RequestParam(value = "sord", required = false) String order) {
    Sort sort = null;
    String orderBy = sortBy;

    if (orderBy != null && orderBy.equals("creationDateString")) orderBy = "creationDate";

    if (orderBy != null && order != null) {
      if (order.equals("desc")) {
        sort = new Sort(Sort.Direction.DESC, orderBy);
      } else sort = new Sort(Sort.Direction.ASC, orderBy);
    }

    PageRequest pageRequest = null;

    System.out.println(page + rows);

    if (sort != null) {
      pageRequest = new PageRequest(page - 1, rows, sort);
    } else {
      pageRequest = new PageRequest(page - 1, rows);
    }

    Page<Question> questionPage = questionService.findAllByPage(pageRequest);

    QuestionGrid questionGrid = new QuestionGrid();

    questionGrid.setCurrentPage(questionPage.getNumber() + 1);
    questionGrid.setTotalPages(questionPage.getTotalPages());
    questionGrid.setTotalRecords(questionPage.getTotalElements());
    questionGrid.setQuestionData(Lists.newArrayList(questionPage.iterator()));

    return questionGrid;
  }
  @WithMockUser(username = "******", password = "******", roles = "ADMIN")
  @Test
  public void testAddProjectSample() {
    Project project = projectService.read(1L);

    Sample sample = sampleService.read(2L);

    projectService.addSampleToProject(project, sample);

    Page<ProjectEvent> eventsForProject =
        projectEventService.getEventsForProject(project, new PageRequest(0, 10));

    assertEquals(1, eventsForProject.getTotalElements());
    ProjectEvent event = eventsForProject.iterator().next();

    assertTrue(event instanceof SampleAddedProjectEvent);
    SampleAddedProjectEvent userEvent = (SampleAddedProjectEvent) event;
    assertEquals(project, userEvent.getProject());
    assertEquals(sample, userEvent.getSample());
  }
  @RequestMapping(value = "/listgrid", method = RequestMethod.GET, produces = "application/json")
  @ResponseBody
  public NodeGrid listGrid(
      @RequestParam(value = "page", required = false) Integer page,
      @RequestParam(value = "rows", required = false) Integer rows,
      @RequestParam(value = "sidx", required = false) String sortBy,
      @RequestParam(value = "sord", required = false) String order) {

    Sort sort = null;
    String orderBy = sortBy;
    if (orderBy != null && orderBy.equals("name")) {
      orderBy = "name";
    }

    if (orderBy != null && order != null) {
      if (order.equals("desc")) {
        sort = new Sort(Sort.Direction.DESC, orderBy);
      } else sort = new Sort(Sort.Direction.ASC, orderBy);
    }

    PageRequest pageRequest = null;
    if (sort != null) {
      pageRequest = new PageRequest(page - 1, rows, sort);
    } else {
      pageRequest = new PageRequest(page - 1, rows);
    }

    Page<Node> nodePage = nodeService.findByPage(pageRequest);
    NodeGrid nodeGrid = new NodeGrid();
    nodeGrid.setCurrentPage(nodePage.getNumber() + 1);
    nodeGrid.setTotalPages(nodePage.getTotalPages());
    nodeGrid.setTotalRecords(nodePage.getTotalElements());
    List<Node> nodes = Lists.newArrayList(nodePage.iterator());
    nodeGrid.setNodeData(checkAccessiblity(nodes));

    return nodeGrid;
  }