Package com.springone.myrestaurants.domain

Examples of com.springone.myrestaurants.domain.UserAccount


    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public String delete(@PathVariable("id") Long id,
                   @ModelAttribute("currentUserAccountId") Long userId,
                     @RequestParam(value = "page", required = false) Integer page,
                     @RequestParam(value = "size", required = false) Integer size, Model model) {
      UserAccount account = this.userAccountRepository.findUserAccount(userId);
      UserAccount friendAccount = this.userAccountRepository.findUserAccount(id);
      if (account.getFriends().contains(friendAccount)) {
        account.getFriends().remove(friendAccount);
      }
        model.addAttribute("page", (page == null) ? "1" : page.toString());
        model.addAttribute("size", (size == null) ? "10" : size.toString());
View Full Code Here


  @RequestMapping(value = "/{id}/{userId}", params = "favorite", method = RequestMethod.PUT)
    public String addFavoriteRestaurant(@PathVariable("id") Long id,
                      @PathVariable("userId") Long userId,
                      Model model) {
    Restaurant restaurant = this.restaurantRepository.findRestaurant(id);
    UserAccount account = this.userAccountRepository.findUserAccount(userId);   
    account.getFavorites().add(restaurant);
    this.userAccountRepository.persist(account);
        addDateTimeFormatPatterns(model);      
        model.addAttribute("useraccount", account);
        model.addAttribute("itemId", id);
        return "redirect:/useraccounts/" + account.getId();
    }
View Full Code Here

  @Autowired
  UserAccountRepository userAccountRepository;

  @ModelAttribute("currentUserAccountId")
  public Long populateModelWithCurrentUserAccountIdAsLong() {
    UserAccount userAccount = getCurrentUserAccount();
    if (userAccount != null) {
      return userAccount.getId();
    } else {
      return -1L;
    }
  }
View Full Code Here

  }

  private UserAccount getCurrentUserAccount() {
    String currentUser = SecurityContextHolder.getContext()
        .getAuthentication().getName();
    UserAccount userAccount = userAccountRepository.findByName(currentUser);
    if (userAccount != null) {
      userAccount.persist();
    }
    return userAccount;
  }
View Full Code Here

    UserAccountRepository repo;

    @Transactional
    @Test
    public void testFindUser() {
      UserAccount o = repo.findUserAccount(userId);
      Assert.assertNotNull("should have found something" ,o);
      Assert.assertEquals("should have found the right one", "user", o.getUserName());
    }
View Full Code Here

    }

    @Transactional
    @Test
    public void testFindByName() {
      UserAccount o = repo.findByName("user");
      Assert.assertNotNull("should have found something" ,o);
      Assert.assertEquals("should have found the right one", "user", o.getUserName());
    }
View Full Code Here

    }

    @Transactional
    @Test
    public void testPersist() {
      UserAccount newUser = new UserAccount();
      newUser.setFirstName("John");
      newUser.setLastName("Doe");
      newUser.setBirthDate(new Date());
      newUser.setNickname("Bubba");
      newUser.setUserName("jdoe");
      repo.persist(newUser);
      em.flush();
    List results = em.createNativeQuery("select id, user_name, first_name from user_account where user_name = ?")
          .setParameter(1, newUser.getUserName()).getResultList();
      Assert.assertEquals("should have found the entry", 1, results.size());
      Assert.assertEquals("should have found the correct entry", "John", ((Object[])results.get(0))[2]);
      UserAccount persistedUser = repo.findByName(newUser.getUserName());
      Assert.assertEquals("should have the correct value", newUser.getFirstName(), persistedUser.getFirstName());
      Assert.assertEquals("should have the correct value", newUser.getLastName(), persistedUser.getLastName());
      Assert.assertEquals("should have the correct value", newUser.getNickname(), persistedUser.getNickname());
      Assert.assertEquals("should have the correct value", newUser.getUserName(), persistedUser.getUserName());
      Assert.assertEquals("should have the correct value", newUser.getBirthDate(), persistedUser.getBirthDate());
    }
View Full Code Here

    @Test
    public void testMerge() {
      EntityManager separateTxEm = emf.createEntityManager();
      EntityTransaction separateTx = separateTxEm.getTransaction();
      separateTx.begin();
      UserAccount user = separateTxEm.find(UserAccount.class, userId);
      separateTxEm.flush();
      Assert.assertTrue("entity is part of separate em", separateTxEm.contains(user));
      separateTx.commit();
      separateTxEm.detach(user);
      Assert.assertFalse("entity is no longer part of separate em", separateTxEm.contains(user));
      Assert.assertFalse("entity is not part of main em", em.contains(user));
      user.setLastName("Hendrix");
      UserAccount mergedUser = repo.merge(user);
      em.flush();
      Assert.assertTrue("entity is now part of main em", em.contains(mergedUser));
    List results = em.createNativeQuery("select id, user_name, last_name from user_account where id = ?")
        .setParameter(1, userId).getResultList();
    Assert.assertEquals("should have found the entry", 1, results.size());
View Full Code Here

  @BeforeTransaction
  public void setUpBeforeTransaction() {
    EntityManager setUpEm = emf.createEntityManager();
    EntityTransaction setUpTx = setUpEm.getTransaction();
    setUpTx.begin();
    UserAccount u = new UserAccount();
    u.setFirstName("Bubba");
    u.setLastName("Jones");
    u.setBirthDate(new Date());
    u.setUserName("user");
    setUpEm.persist(u);
    setUpEm.flush();
        u.persist();
    this.userId = u.getId();
    setUpTx.commit();
  }
View Full Code Here

  @AfterTransaction
  public void tearDown() {
    EntityManager tearDownEm = emf.createEntityManager();
    EntityTransaction tearDownTx = tearDownEm.getTransaction();
    tearDownTx.begin();
    UserAccount u = tearDownEm.find(UserAccount.class, this.userId);
    tearDownEm.remove(u);
    tearDownEm.flush();
    tearDownTx.commit();     
  }
View Full Code Here

TOP

Related Classes of com.springone.myrestaurants.domain.UserAccount

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.