• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / jpetstore-6 / 2384

25 Jul 2026 02:39AM UTC coverage: 83.278% (+11.3%) from 72.006%
2384

Pull #1076

github

web-flow
Merge c4f0bb4d2 into 2117c6fa6
Pull Request #1076: Migrate JPetstore to Jakarta EE

47 of 98 branches covered (47.96%)

107 of 197 new or added lines in 5 files covered. (54.31%)

498 of 598 relevant lines covered (83.28%)

0.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/src/main/java/org/mybatis/jpetstore/web/controllers/AccountController.java
1
/*
2
 *    Copyright 2010-2026 the original author or authors.
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16
package org.mybatis.jpetstore.web.controllers;
17

18
import jakarta.servlet.http.HttpSession;
19

20
import java.util.List;
21

22
import org.mybatis.jpetstore.domain.Account;
23
import org.mybatis.jpetstore.domain.Product;
24
import org.mybatis.jpetstore.service.AccountService;
25
import org.mybatis.jpetstore.service.CatalogService;
26
import org.springframework.beans.factory.annotation.Autowired;
27
import org.springframework.stereotype.Controller;
28
import org.springframework.ui.Model;
29
import org.springframework.web.bind.annotation.GetMapping;
30
import org.springframework.web.bind.annotation.ModelAttribute;
31
import org.springframework.web.bind.annotation.PostMapping;
32
import org.springframework.web.bind.annotation.RequestMapping;
33
import org.springframework.web.bind.annotation.RequestParam;
34

35
@Controller
36
@RequestMapping("/account")
37
public class AccountController {
1✔
38

39
  private static final String SIGNON_VIEW = "account/SignonForm";
40
  private static final String NEW_ACCOUNT_VIEW = "account/NewAccountForm";
41
  private static final String EDIT_ACCOUNT_VIEW = "account/EditAccountForm";
42

43
  private static final List<String> LANGUAGE_LIST = List.of("english", "japanese");
1✔
44
  private static final List<String> CATEGORY_LIST = List.of("FISH", "DOGS", "REPTILES", "CATS", "BIRDS");
1✔
45

46
  @Autowired
47
  private AccountService accountService;
48
  @Autowired
49
  private CatalogService catalogService;
50

51
  @GetMapping({ "", "/" })
52
  public String signonForm() {
53
    return SIGNON_VIEW;
1✔
54
  }
55

56
  @PostMapping("/signon")
57
  public String signon(@RequestParam("username") String username, @RequestParam("password") String password,
58
      HttpSession session, Model model) {
59
    Account account = accountService.getAccount(username, password);
1✔
60
    if (account == null) {
1✔
61
      model.addAttribute("message", "Invalid username or password.  Signon failed.");
1✔
62
      return SIGNON_VIEW;
1✔
63
    }
64
    account.setPassword(null);
1✔
65
    List<Product> myList = catalogService.getProductListByCategory(account.getFavouriteCategoryId());
1✔
66
    session.setAttribute("accountBean", new AccountSession(account, myList, true));
1✔
67
    return "redirect:/catalog";
1✔
68
  }
69

70
  @GetMapping("/signoff")
71
  public String signoff(HttpSession session) {
NEW
72
    session.invalidate();
×
NEW
73
    return "redirect:/catalog";
×
74
  }
75

76
  @GetMapping("/new")
77
  public String newAccountForm(Model model) {
78
    model.addAttribute("languages", LANGUAGE_LIST);
1✔
79
    model.addAttribute("categories", CATEGORY_LIST);
1✔
80
    model.addAttribute("account", new Account());
1✔
81
    return NEW_ACCOUNT_VIEW;
1✔
82
  }
83

84
  @PostMapping("/new")
85
  public String newAccount(@ModelAttribute Account account, HttpSession session) {
86
    accountService.insertAccount(account);
1✔
87
    return "redirect:/catalog";
1✔
88
  }
89

90
  @GetMapping("/edit")
91
  public String editAccountForm(HttpSession session, Model model) {
NEW
92
    AccountSession accountSession = (AccountSession) session.getAttribute("accountBean");
×
NEW
93
    if (accountSession != null) {
×
NEW
94
      model.addAttribute("account", accountSession.getAccount());
×
95
    }
NEW
96
    model.addAttribute("languages", LANGUAGE_LIST);
×
NEW
97
    model.addAttribute("categories", CATEGORY_LIST);
×
NEW
98
    return EDIT_ACCOUNT_VIEW;
×
99
  }
100

101
  @PostMapping("/edit")
102
  public String editAccount(@ModelAttribute Account account, HttpSession session) {
103
    accountService.updateAccount(account);
1✔
104
    Account updatedAccount = accountService.getAccount(account.getUsername());
1✔
105
    List<Product> myList = catalogService.getProductListByCategory(updatedAccount.getFavouriteCategoryId());
1✔
106
    session.setAttribute("accountBean", new AccountSession(updatedAccount, myList, true));
1✔
107
    return "redirect:/account/edit";
1✔
108
  }
109

110
  /**
111
   * Inner class to hold account session data, compatible with JSP ${sessionScope.accountBean.*} references.
112
   */
113
  public static class AccountSession implements java.io.Serializable {
114
    private static final long serialVersionUID = 1L;
115
    private final Account account;
116
    private final List<Product> myList;
117
    private final boolean authenticated;
118

119
    public AccountSession(Account account, List<Product> myList, boolean authenticated) {
1✔
120
      this.account = account;
1✔
121
      this.myList = myList;
1✔
122
      this.authenticated = authenticated;
1✔
123
    }
1✔
124

125
    public Account getAccount() {
126
      return account;
1✔
127
    }
128

129
    public List<Product> getMyList() {
NEW
130
      return myList;
×
131
    }
132

133
    public boolean isAuthenticated() {
134
      return authenticated && account != null && account.getUsername() != null;
1!
135
    }
136
  }
137
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc