@Test public void testCRUDAccount() { // Create Account account = new Account(); account.setGivenName("Anthony"); account.setSurname("Wolski"); account.setEmail("*****@*****.**"); account.setPassword("password"); account.setUsername("awolski"); accountService.createAccount(account); assertEquals(new Long(0), account.getVersion()); // Read Account found = accountService.getAccount(account.getId()); assertEquals("Anthony", found.getGivenName()); assertEquals("Wolski", found.getSurname()); assertEquals("*****@*****.**", found.getEmail()); assertEquals("password", found.getPassword()); assertEquals("awolski", found.getUsername()); assertEquals(new Long(0), account.getVersion()); // Update account.setMiddleName("Keith"); accountService.saveAccount(account); account = accountService.getAccount(account.getId()); assertEquals(new Long(1), account.getVersion()); // Delete String accountId = account.getId(); accountService.deleteAccountById(accountId); account = accountService.getAccount(accountId); assertNull(account); }
@Test public void testCreateGroupMembership() { Account account = new Account(); account.setGivenName("Anthony"); account.setSurname("Wolski"); account.setEmail("*****@*****.**"); account.setPassword("password"); account.setUsername("awolski"); accountService.createAccount(account); Group group = new Group(); group.setName("Test Group"); accountService.createGroup(group); GroupMembership groupMembership = new GroupMembership(account, group); accountService.createGroupMembership(groupMembership); List<Account> groupAccounts = accountService.getGroupAccounts(group.getId()); assertEquals(1, groupAccounts.size()); List<Group> accountGroups = accountService.getAccountGroups(account.getId()); assertEquals(1, accountGroups.size()); List<GroupMembership> groupGroupMemberships = accountService.getGroupGroupMemberships(group.getId()); assertEquals(1, groupGroupMemberships.size()); List<GroupMembership> accountGroupMemberships = accountService.getAccountGroupMemberships(account.getId()); assertEquals(1, accountGroupMemberships.size()); }
/** * Brief data * * @param uid * @param password * @param firstName * @param surname * @param email * @param phone * @param org * @param description * @return */ public static Account createBrief( String uid, String password, String firstName, String surname, String email, String phone, String org, String title, String description) { Account account = new AccountImpl(); account.setUid(uid); account.setPassword(password); account.setGivenName(firstName); account.setSurname(surname); account.setCommonName(formatCommonName(firstName, surname)); account.setEmail(email); account.setPhone(phone); account.setOrg(org); account.setTitle(title); account.setDescription(description); return account; }
public ArrayList<Account> getAccountList() { Connection connect = null; try { ArrayList<Account> accounts = new ArrayList<>(); connect = DBConnection.getConnection(); String sql = "SELECT * FROM account" + "ORDER BY name desc"; ResultSet result = Utility.queryOperation(connect, sql); Account temp = new Account(); while (result.next()) { temp.setName(result.getString("name")); temp.setEmail(result.getString("email")); temp.setSecondaryEmail(result.getString("secondaryEmail")); temp.setTypeAccount(result.getString("typeAccount")); temp.setPassword(result.getString("password")); temp.setAdmin(result.getBoolean("isAdministrator")); accounts.add(temp); } return accounts; } catch (SQLException ex) { Logger.getLogger(AccountManager.class.getName()).log(Level.SEVERE, null, ex); } finally { DBConnection.releaseConnection(connect); } return null; }
public ArrayList<Account> searchUser(String search, String type) throws SQLException { Connection connect = null; ArrayList<Account> accounts; String sql = "SELECT * from account WHERE " + "name LIKE '%" + search + "%'" + "AND typeAccount = '" + type + "'"; String sql2 = "SELECT * from account WHERE " + "typeAccount ='" + type + "'"; try { connect = DBConnection.getConnection(); accounts = new ArrayList<>(); if (search.isEmpty()) { ResultSet result = Utility.queryOperation(connect, sql2); Account temp = new Account(); while (result.next()) { temp.setName(result.getString("name")); temp.setEmail(result.getString("email")); temp.setSecondaryEmail(result.getString("secondaryEmail")); temp.setTypeAccount(result.getString("typeAccount")); temp.setPassword(result.getString("password")); temp.setAdmin(result.getBoolean("isAdministrator")); accounts.add(temp); } } else { ResultSet result = Utility.queryOperation(connect, sql); Account temp = new Account(); while (result.next()) { temp.setName(result.getString("name")); temp.setEmail(result.getString("email")); temp.setSecondaryEmail(result.getString("secondaryEmail")); temp.setTypeAccount(result.getString("typeAccount")); temp.setPassword(result.getString("password")); temp.setAdmin(result.getBoolean("isAdministrator")); accounts.add(temp); } } } finally { DBConnection.releaseConnection(connect); } return accounts; }
public Account getAccount() { Account account = null; String username = mPreference.getString(USERNAME_KEY, null); if (!TextUtils.isEmpty(username)) { account = new Account(); account.setUsername(username); account.setPassword(mPreference.getString(PASSWORD_KEY, null)); } return account; }
@Transactional public Account save(Account account) { account.setPassword(passwordEncoder.encode(account.getPassword())); accountRepository.save(account); return account; }
@Transactional public Account save(Account account) { account.setPassword(passwordEncoder.encode(account.getPassword())); entityManager.persist(account); return account; }