use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class AccountManageServiceCommonImpl method saveAccount.
/**
* {@inheritDoc}
*
* @see AccountManageService#saveAccount(AccountInfo)
*/
@Override
public Account saveAccount(AccountInfo accountInfo) {
if (accountInfo == null) {
throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
}
try {
String accountId = accountInfo.getAccountId();
Account account;
if (!StringUtils.isBlank(accountId)) {
account = accessor.getById(accountId, Account.class);
if (account == null) {
if (logger.isErrorEnabled()) {
logger.error(String.format("The Account entity[%s] not found.", accountId));
}
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOT_FOUND);
}
// 这里不允许修改密码,密码必须通过另外途径进行修改
} else {
String password = accountInfo.getPassword();
if (StringUtils.isBlank(password)) {
password = "ds110119";
}
account = EntityFactory.createEntity(Account.class);
account.setPassword(DigestUtils.md5(password));
}
account.setCode(accountInfo.getCode());
if (StringUtils.isBlank(accountInfo.getOwnerId())) {
if (!"admin".equals(accountInfo.getCode())) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOALLOCATE_USER);
}
} else {
User owner = accessor.getById(accountInfo.getOwnerId(), User.class);
if (owner == null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND);
}
account.setOwner(owner);
account.setName(owner.getFullName());
}
account.setDesc(accountInfo.getDesc());
if (account.getRoles() != null && !account.getRoles().isEmpty()) {
account.getRoles().clear();
}
for (String roleId : accountInfo.getRoleIds()) {
Role role = accessor.getById(roleId, Role.class);
if (role == null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ROLE_NOT_FOUND);
}
account.getRoles().add(role);
}
account.setValid(accountInfo.isValid());
account = this.save(account);
if (operateLogService != null) {
operateLogService.writeLog(String.format("保存账户[code=%s, name=%s]成功。", account.getCode(), account.getName()));
}
return account;
} catch (UserInterfaceDalErrorException ex) {
if (logger.isErrorEnabled()) {
logger.error(ex);
}
throw new UserInterfaceDalErrorException(UserInterfaceDalErrorException.DalErrors.DB_OPERATE_FAIL);
} catch (NoSuchAlgorithmException ex) {
if (logger.isErrorEnabled()) {
logger.error(ex);
}
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_DIGEST_PASSWORD_FAIL);
}
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class UserManageServiceCommonImpl method allocateAccount.
/**
* {@inheritDoc}
*
* @see UserManageService#allocateAccount(AccountManageService.AccountInfo)
*/
@Override
public Account allocateAccount(AccountManageService.AccountInfo accountInfo) {
if (accountInfo == null || StringUtils.isBlank(accountInfo.getOwnerId()) || StringUtils.isBlank(accountInfo.getCode())) {
throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
}
User user = accessor.getById(accountInfo.getOwnerId(), User.class);
if (user == null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND);
}
Account account = accessor.getByCode(accountInfo.getCode(), Account.class);
if (account != null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_HAS_EXIST);
}
account = accountManageService.saveAccount(accountInfo);
if (operateLogService != null) {
operateLogService.writeLog(String.format("为用户[%s]分配账户[%s]成功。", user.getFullName(), account.getCode()));
}
return account;
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class UserManageServiceCommonImpl method saveUser.
/**
* {@inheritDoc}
*
* @see UserManageService#saveUser(UserInfo)
*/
@Override
public User saveUser(UserInfo userInfo) {
if (userInfo == null) {
throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
}
String userId = userInfo.getUserId();
User user;
if (!StringUtils.isBlank(userId)) {
user = accessor.getById(userId, User.class);
if (user == null) {
if (logger.isErrorEnabled()) {
logger.error(String.format("The User entity[%s] not found.", userId));
}
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND);
}
} else {
user = EntityFactory.createEntity(User.class);
}
if (!StringUtils.isBlank(userInfo.getDepartId())) {
Department depart = accessor.getById(userInfo.getDepartId(), Department.class);
if (depart == null) {
throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.DEPARTMENT_NOT_FOUND);
}
user.setDepartment(depart);
} else {
user.setDepartment(null);
}
long birthday = userInfo.getBirthday();
if (birthday > 0) {
user.setBirthday(new Date(birthday));
}
user.setDesc(userInfo.getDesc());
user.setFirstName(userInfo.getFirstName());
user.setMiddleName(userInfo.getMiddleName());
user.setLastName(userInfo.getLastName());
user.setSex(userInfo.getSex());
user.setStation(userInfo.getStation());
user.setValid(userInfo.isValid());
user = this.save(user);
if (operateLogService != null) {
operateLogService.writeLog(String.format("保存用户[name=%s]信息成功。", user.getFullName()));
}
return user;
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class UserManageResource method listUsersPagination.
@Path("users")
@POST
@AuthenticateAround(returnValueClass = PaginationDataVO.class)
public PaginationDataVO<List<UserVO>> listUsersPagination(Pagination pagination) {
if (pagination == null) {
pagination = new Pagination();
}
try {
List<User> users = accessor.list(pagination, User.class);
List<UserVO> userVOs = UserVO.transform(users);
return new PaginationDataVO<>(pagination, userVOs);
} catch (UserInterfaceException ex) {
return new PaginationDataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("List users fail.", ex);
}
return new PaginationDataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class UserManageResource method newUser.
@Path("users/new")
@POST
@AuthenticateAround(returnValueClass = DataVO.class)
public DataVO<UserVO> newUser(@QueryParam("userCode") String userCode, UserInfoVO userInfoVO) {
sessionDataStore.setCurrentUserCode(userCode);
try {
userInfoVO.setId(null);
User user = userManageService.saveUser(userInfoVO.getUserInfo());
UserVO userVO = UserVO.transform(user);
sessionDataStore.removeCurrentUserCode();
return new DataVO<>(userVO);
} catch (UserInterfaceException ex) {
return new DataVO<>(ex);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Create a user fail.", ex);
}
return new DataVO<>(new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_OTHER_FAIL));
}
}
Aggregations