@RequestMapping(method = RequestMethod.GET)
  public String list(
      @RequestParam(required = false) String p,
      @RequestParam(required = false) String s,
      @RequestParam(required = false) String f,
      HttpServletRequest request,
      ModelMap model,
      @ModelAttribute("success") String success,
      @ModelAttribute("error") String error) {
    PageState pageState = new PageState();
    pageState.setPage(PageHelper.parsePage(p));
    pageState.setSortColumn(PageHelper.parseSortColumn(s));
    pageState.setFilter(PageHelper.parseFilter(f));

    ComputersAndCount computersAndCount = computerService.findAllAndCount(pageState);

    pageState.setTotal(computersAndCount.getTotal());
    model.addAttribute("computers", computersAndCount.getComputers());

    // Now that we computed everything
    model.addAttribute("state", pageState);

    // Flash notices
    model.addAttribute("success", success);
    model.addAttribute("error", error);

    return "/index";
  }
Exemple #2
0
 public void test_getPageState_createNewPageState() {
   PageState state = PageState.getPageState(cr, "id123", true);
   assertNotNull("page state not null", state.properties.size());
   assertEquals("defined page ids", "id123", getPageIds(cr));
   PageState.getPageState(cr, "abc", true);
   assertEquals("defined page ids", "abc, id123", getPageIds(cr));
 }
Exemple #3
0
 public void test_removeEldestEntry_lruReplacement() {
   PageState.maxPageStates = 3;
   Config.setDataset("main", new Dataset("maxPageStates", "4"));
   PageState.getPageState(cr, "id1", true);
   PageState.getPageState(cr, "id2", true);
   PageState.getPageState(cr, "id3", true);
   assertEquals("page ids before replacement", "id1, id2, id3", getPageIds(cr));
   PageState.getPageState(cr, "id4", true);
   assertEquals("page ids after replacement", "id2, id3, id4", getPageIds(cr));
 }
Exemple #4
0
 public void test_getPageProperty() {
   PageState state1 = PageState.getPageState(cr, "id123", true);
   PageState state2 = PageState.getPageState(cr, "abc", true);
   state1.setPageProperty("first", "123");
   state1.setPageProperty("second", "456");
   state2.setPageProperty("third", "789");
   assertEquals("value of first property", "123", state1.getPageProperty("first"));
   assertEquals("value of third property", "789", state2.getPageProperty("third"));
   assertEquals("missing property", null, state2.getPageProperty("first"));
 }
Exemple #5
0
 /** @overrides ISupportMomento.getState */
 @Override
 public Object getState() {
   PageState state = new PageState();
   // Populate basic page information
   state.name = getPageName();
   state.id = getPageId();
   state.color = getPageColor();
   state.width = this.pageJComponent.getWidth();
   // Fill in block information
   for (RenderableBlock rb : this.getBlocks()) {
     state.renderableBlocks.put(rb.getBlockID(), rb.getState());
   }
   return state;
 }
Exemple #6
0
 public void test_setPageProperty() {
   PageState state1 = PageState.getPageState(cr, "id123", true);
   PageState state2 = PageState.getPageState(cr, "abc", true);
   state1.setPageProperty("first", "123");
   state1.setPageProperty("second", "456");
   state2.setPageProperty("third", "789");
   assertEquals("properties in first PageState", "first, second", getPropertyNames(state1));
   assertEquals("properties in second PageState", "third", getPropertyNames(state2));
 }
Exemple #7
0
 public void test_removeEldestEntry_maxPageStatesNotDefined() {
   PageState.maxPageStates = -1;
   Config.setDataset("main", new Dataset());
   boolean gotException = false;
   try {
     PageState.getPageState(cr, "id123", true);
   } catch (Dataset.MissingValueError e) {
     assertEquals(
         "exception message", "couldn't find dataset element \"maxPageStates\"", e.getMessage());
     gotException = true;
   }
   assertEquals("exception happened", true, gotException);
 }
Exemple #8
0
  public void test_removeEldestEntry_maxPageStatesValueBogus() {
    PageState.maxPageStates = -1;
    Config.setDataset("main", new Dataset("maxPageStates", "7bogus8"));

    boolean gotException = false;
    try {
      PageState.getPageState(cr, "id123", true);
    } catch (InternalError e) {
      assertEquals(
          "exception message",
          "bad value \"7bogus8\" for maxPageStates configuration " + "option: must be an integer",
          e.getMessage());
      gotException = true;
    }
    assertEquals("exception happened", true, gotException);
  }
Exemple #9
0
  public void test_flushPageState() {
    PageState state1 = PageState.getPageState(cr, "id123", true);
    PageState state2 = PageState.getPageState(cr, "abc", true);
    state1.setPageProperty("first", "123");
    state1.setPageProperty("second", "456");
    state2.setPageProperty("third", "789");

    // Without deleting AllPageState.
    state1.flushPageState(cr);
    PageState.AllPageInfo pageInfo1 =
        (PageState.AllPageInfo) cr.getServletRequest().getSession().getAttribute("fiz.PageState");
    assertEquals("AllPageInfo has state1", state1, pageInfo1.get("id123"));
    assertEquals("AllPageInfo has state2", state2, pageInfo1.get("abc"));

    // With AllPageState deleted.
    cr.getServletRequest().getSession().removeAttribute("fiz.PageState");
    cr.pageId = "id123";
    state1.flushPageState(cr);
    PageState.AllPageInfo pageInfo2 =
        (PageState.AllPageInfo) cr.getServletRequest().getSession().getAttribute("fiz.PageState");
    assertEquals("AllPageInfo has state1", state1, pageInfo2.get("id123"));
    assertEquals("AllPageInfo has only one PageState", 1, pageInfo2.size());
  }
Exemple #10
0
 public void test_getPageState_createFalse() {
   PageState state = PageState.getPageState(cr, "id123", false);
   assertEquals("no page state", null, state);
   assertEquals("defined page ids", "", getPageIds(cr));
 }
Exemple #11
0
 public void test_removeEldestEntry_setMaxPageStates() {
   PageState.maxPageStates = -1;
   Config.setDataset("main", new Dataset("maxPageStates", "7"));
   PageState.getPageState(cr, "id123", true);
   assertEquals("maxPageStates", 7, PageState.maxPageStates);
 }