Search in sources :

Example 1 with FfeeAccount

use of org.mx.tools.ffee.dal.entity.FfeeAccount in project main by JohnPeng739.

the class FfeeAccountManageServiceImpl method regist.

/**
 * 使用用户名、密码方式注册账户。
 *
 * @see FfeeAccountManageService#regist(String, String, String)
 */
@Override
@Transactional()
public FfeeAccount regist(String code, String name, String password) {
    if (StringUtils.isBlank(code) || StringUtils.isBlank(name) || StringUtils.isBlank(password)) {
        throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
    }
    Account account = accessor.getByCode(code, Account.class);
    if (account != null) {
        throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_HAS_EXIST);
    }
    Role role = accessor.getByCode("user", Role.class);
    if (role == null) {
        throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ROLE_NOT_FOUND);
    }
    account = EntityFactory.createEntity(Account.class);
    account.setCode(code);
    account.setName(name);
    try {
        account.setPassword(DigestUtils.md5(password));
    } catch (NoSuchAlgorithmException ex) {
        if (logger.isErrorEnabled()) {
            logger.error("Digest the password fail.", ex);
        }
        throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_DIGEST_PASSWORD_FAIL);
    }
    account = accessor.save(account, false);
    FfeeAccount ffeeAccount = EntityFactory.createEntity(FfeeAccount.class);
    ffeeAccount.setAccount(account);
    ffeeAccount.setSourceType(FfeeAccount.AccountSourceType.NORMAL);
    ffeeAccount = accessor.save(ffeeAccount, false);
    if (operateLogService != null) {
        operateLogService.writeLog(String.format("常规账户[%s]注册成功。", name));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Create a normal registry FFEE account[%s - %s] successfully.", code, name));
    }
    return ffeeAccount;
}
Also used : Role(org.mx.comps.rbac.dal.entity.Role) FfeeAccount(org.mx.tools.ffee.dal.entity.FfeeAccount) Account(org.mx.comps.rbac.dal.entity.Account) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) FfeeAccount(org.mx.tools.ffee.dal.entity.FfeeAccount) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with FfeeAccount

use of org.mx.tools.ffee.dal.entity.FfeeAccount in project main by JohnPeng739.

the class FamilyManageServiceImpl method createFamily.

/**
 * {@inheritDoc}
 *
 * @see FamilyManageService#createFamily(String, String, String)
 */
@Transactional()
public Family createFamily(String name, String ffeeAccountId, String memberRole) {
    Family family = getFamily(null, name);
    if (family != null) {
        throw new UserInterfaceFfeeErrorException(UserInterfaceFfeeErrorException.FfeeErrors.FAMILY_EXISTED);
    }
    FfeeAccount ffeeAccount = accessor.getById(ffeeAccountId, FfeeAccount.class);
    if (ffeeAccount == null) {
        throw new UserInterfaceFfeeErrorException(UserInterfaceFfeeErrorException.FfeeErrors.ACCOUNT_NOT_EXISTED);
    }
    FamilyMember member = EntityFactory.createEntity(FamilyMember.class);
    member.setFfeeAccount(ffeeAccount);
    member.setMemberRole(memberRole);
    member = accessor.save(member, false);
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Create a new family member, account: %s, family: %s.", ffeeAccount.getAccount().getName(), name));
    }
    family = EntityFactory.createEntity(Family.class);
    family.setName(name);
    family.setOwner(ffeeAccount);
    family.getMembers().add(member);
    family = accessor.save(family, false);
    if (operateLogService != null) {
        operateLogService.writeLog(String.format("成功创建家庭[%s],家主是账户[%s]。", family.getName(), ffeeAccount.getAccount().getName()));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Create the family[%s] successfully, account: %s.", family.getName(), ffeeAccount.getAccount().getName()));
    }
    return family;
}
Also used : FfeeAccount(org.mx.tools.ffee.dal.entity.FfeeAccount) FamilyMember(org.mx.tools.ffee.dal.entity.FamilyMember) UserInterfaceFfeeErrorException(org.mx.tools.ffee.error.UserInterfaceFfeeErrorException) Family(org.mx.tools.ffee.dal.entity.Family) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with FfeeAccount

use of org.mx.tools.ffee.dal.entity.FfeeAccount in project main by JohnPeng739.

the class FamilyManageServiceImpl method joinFamily.

/**
 * {@inheritDoc}
 *
 * @see FamilyManageService#joinFamily(String, String, String)
 */
@Transactional()
public Family joinFamily(String familyId, String ffeeAccountId, String memberRole) {
    Family family = getFamily(familyId, null);
    if (family == null) {
        throw new UserInterfaceFfeeErrorException(UserInterfaceFfeeErrorException.FfeeErrors.FAMILY_NOT_EXISTED);
    }
    FfeeAccount ffeeAccount = accessor.getById(ffeeAccountId, FfeeAccount.class);
    if (ffeeAccount == null) {
        throw new UserInterfaceFfeeErrorException(UserInterfaceFfeeErrorException.FfeeErrors.ACCOUNT_NOT_EXISTED);
    }
    Set<FamilyMember> members = family.getMembers();
    while (members != null && members.iterator().hasNext()) {
        FamilyMember member = members.iterator().next();
        if (member != null && member.getFfeeAccount() != null && ffeeAccountId.equals(member.getFfeeAccount().getId())) {
            throw new UserInterfaceFfeeErrorException(UserInterfaceFfeeErrorException.FfeeErrors.ACCOUNT_IN_MEMBERS);
        }
    }
    FamilyMember member = EntityFactory.createEntity(FamilyMember.class);
    member.setFfeeAccount(ffeeAccount);
    member.setMemberRole(memberRole);
    member = accessor.save(member, false);
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Create a new family member, account: %s, family: %s.", ffeeAccount.getAccount().getName(), family.getName()));
    }
    if (members == null) {
        throw new UserInterfaceFfeeErrorException(UserInterfaceFfeeErrorException.FfeeErrors.FAMILY_MEMBER_SAVE_FAIL);
    }
    members.add(member);
    family = accessor.save(family, false);
    if (operateLogService != null) {
        operateLogService.writeLog(String.format("账户[%s]成功加入家庭[%s]。", ffeeAccount.getAccount().getName(), family.getName()));
    }
    if (logger.isDebugEnabled()) {
        logger.debug(String.format("Account[%s] join the family[%s] successfully.", ffeeAccount.getAccount().getName(), family.getName()));
    }
    return family;
}
Also used : FfeeAccount(org.mx.tools.ffee.dal.entity.FfeeAccount) FamilyMember(org.mx.tools.ffee.dal.entity.FamilyMember) UserInterfaceFfeeErrorException(org.mx.tools.ffee.error.UserInterfaceFfeeErrorException) Family(org.mx.tools.ffee.dal.entity.Family) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

FfeeAccount (org.mx.tools.ffee.dal.entity.FfeeAccount)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Family (org.mx.tools.ffee.dal.entity.Family)2 FamilyMember (org.mx.tools.ffee.dal.entity.FamilyMember)2 UserInterfaceFfeeErrorException (org.mx.tools.ffee.error.UserInterfaceFfeeErrorException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Account (org.mx.comps.rbac.dal.entity.Account)1 Role (org.mx.comps.rbac.dal.entity.Role)1 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)1 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)1