use of cn.edu.zjnu.acm.judge.data.excel.Account in project judge by zjnu-acm.
the class AccountService method prepare.
private void prepare(Collection<Account> accounts) {
for (Account account : accounts) {
if (!StringUtils.hasText(account.getId())) {
throw new BusinessException(BusinessCode.EMPTY_USER_ID);
}
String password = account.getPassword();
if (StringUtils.isEmpty(password)) {
throw new BusinessException(BusinessCode.EMPTY_PASSWORD);
}
if (password.length() <= PasswordConfiguration.MAX_PASSWORD_LENGTH) {
ValueCheck.checkPassword(password);
account.setPassword(passwordEncoder.encode(password));
}
if (!StringUtils.hasText(account.getEmail())) {
account.setEmail(null);
}
if (!StringUtils.hasText(account.getNick())) {
account.setNick(account.getId());
}
if (account.getSchool() == null) {
account.setSchool("");
}
}
}
use of cn.edu.zjnu.acm.judge.data.excel.Account in project judge by zjnu-acm.
the class AccountService method parseExcel.
public List<Account> parseExcel(InputStream inputStream, @Nullable Locale locale) throws IOException {
List<Account> accounts = ExcelUtil.parse(inputStream, Account.class, locale).stream().filter(account -> StringUtils.hasText(account.getId())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(accounts)) {
return accounts;
}
Map<String, List<Account>> groupBy = accounts.stream().collect(Collectors.groupingBy(Account::getId, () -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER), Collectors.toList()));
List<String> exists = userMapper.findAllByUserIds(groupBy.keySet());
for (String exist : exists) {
for (Account account : groupBy.get(exist)) {
account.setExists(true);
}
}
return accounts;
}
use of cn.edu.zjnu.acm.judge.data.excel.Account in project judge by zjnu-acm.
the class AccountControllerTest method testImportUsers.
/**
* Test of importUsers method, of class AccountController.
*
* @see AccountController#importUsers(AccountImportForm)
*/
@Test
public void testImportUsers() throws Exception {
log.info("importUsers");
AccountImportForm form = new AccountImportForm();
Account account = toAccount(mockDataService.user(false));
Account account2 = toAccount(mockDataService.user(false));
form.setContent(Arrays.asList(account, account2));
expect(form, HttpStatus.OK);
account.setExists(true);
account2.setExists(true);
expect(form, HttpStatus.BAD_REQUEST);
form.setExistsPolicy(Arrays.asList(AccountImportForm.ExistPolicy.ENABLE));
expect(form, HttpStatus.OK);
}
use of cn.edu.zjnu.acm.judge.data.excel.Account in project judge by zjnu-acm.
the class AccountControllerTest method toAccount.
private Account toAccount(User user) {
Account account = new Account();
account.setId(user.getId());
account.setPassword(user.getPassword());
account.setEmail(user.getEmail());
account.setSchool(user.getSchool());
return account;
}
use of cn.edu.zjnu.acm.judge.data.excel.Account in project judge by zjnu-acm.
the class AccountServiceImpl method prepare.
private void prepare(Collection<Account> accounts) {
for (Account account : accounts) {
if (!StringUtils.hasText(account.getId())) {
throw new BusinessException(BusinessCode.IMPORT_USER_ID_EMPTY);
}
String password = account.getPassword();
if (!StringUtils.hasLength(password)) {
throw new BusinessException(BusinessCode.EMPTY_PASSWORD);
}
if (password.length() <= PasswordConfiguration.MAX_PASSWORD_LENGTH) {
ValueCheck.checkPassword(password);
account.setPassword(passwordEncoder.encode(password));
}
if (!StringUtils.hasText(account.getEmail())) {
account.setEmail(null);
}
if (!StringUtils.hasText(account.getNick())) {
account.setNick(account.getId());
}
if (account.getSchool() == null) {
account.setSchool("");
}
}
}
Aggregations