Search in sources :

Example 11 with EntityAccessException

use of org.mx.dal.exception.EntityAccessException in project main by JohnPeng739.

the class UserManageServiceImpl method changePassword.

/**
 * {@inheritDoc}
 *
 * @see UserManageService#changePassword(String, String, String)
 */
@Transactional
@Override
public User changePassword(String userCode, String oldPassword, String newPassword) throws UserInterfaceErrorException {
    try {
        User user = accessor.getByCode(userCode, User.class);
        if (user == null) {
            throw new UserInterfaceErrorException(UserInterfaceErrors.USER_NOT_FOUND);
        }
        try {
            String digestPwd = DigestUtils.md5(oldPassword);
            if (!digestPwd.equals(user.getPassword())) {
                throw new UserInterfaceErrorException(UserInterfaceErrors.USER_PASSWORD_UNMATCH);
            }
            digestPwd = DigestUtils.md5(newPassword);
            user.setPassword(digestPwd);
            user = accessor.save(user);
            logService.writeLog(String.format("成功修改了用户[%s]的密码。", userCode));
            return user;
        } catch (NoSuchAlgorithmException ex) {
            throw new UserInterfaceErrorException(UserInterfaceErrors.USER_PASSWORD_DISGEST_FAIL);
        }
    } catch (EntityAccessException ex) {
        throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
    }
}
Also used : User(com.ds.retl.dal.entity.User) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with EntityAccessException

use of org.mx.dal.exception.EntityAccessException in project main by JohnPeng739.

the class UserManageServiceImpl method saveUser.

/**
 * {@inheritDoc}
 *
 * @see UserManageService#saveUser(User)
 */
@Transactional
@Override
public User saveUser(User user) throws UserInterfaceErrorException {
    try {
        user = accessor.save(user);
        logService.writeLog(String.format("成功新增了用户[%s]。", user.getCode()));
        return user;
    } catch (EntityAccessException ex) {
        throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
    }
}
Also used : UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with EntityAccessException

use of org.mx.dal.exception.EntityAccessException in project main by JohnPeng739.

the class UserManageServiceImpl method login.

/**
 * {@inheritDoc}
 *
 * @see UserManageService#login(String, String)
 */
@Transactional
@Override
public User login(String userCode, String password) throws UserInterfaceErrorException {
    try {
        User user = accessor.getByCode(userCode, User.class);
        if (user == null) {
            throw new UserInterfaceErrorException(UserInterfaceErrors.USER_NOT_FOUND);
        }
        try {
            String digestPwd = DigestUtils.md5(password);
            if (digestPwd.equals(user.getPassword())) {
                // 写入登录成功的日志
                user.setOnline(true);
                user = accessor.save(user);
                logService.writeLog(String.format("用户[%s]成功登录进入系统。", userCode));
                return user;
            } else {
                throw new UserInterfaceErrorException(UserInterfaceErrors.USER_PASSWORD_UNMATCH);
            }
        } catch (NoSuchAlgorithmException ex) {
            throw new UserInterfaceErrorException(UserInterfaceErrors.USER_PASSWORD_DISGEST_FAIL);
        }
    } catch (EntityAccessException ex) {
        throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
    }
}
Also used : User(com.ds.retl.dal.entity.User) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with EntityAccessException

use of org.mx.dal.exception.EntityAccessException in project main by JohnPeng739.

the class TopologyManageResource method getTopology.

/**
 * 根据拓扑数据库ID获取拓扑信息
 *
 * @param topologyId 关键字ID,不是集群中的ID
 * @return 拓扑值对象
 */
@Path("topology")
@GET
public DataVO<TopologyVO> getTopology(@QueryParam("topologyId") String topologyId) {
    try {
        Topology topology = accessor.getById(topologyId, Topology.class);
        TopologyVO vo = new TopologyVO();
        TopologyVO.transform(topology, vo);
        return new DataVO<>(vo);
    } catch (EntityAccessException ex) {
        if (logger.isErrorEnabled()) {
            logger.error(ex);
        }
        return new DataVO<>(new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL));
    }
}
Also used : PaginationDataVO(org.mx.rest.vo.PaginationDataVO) DataVO(org.mx.rest.vo.DataVO) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) Topology(com.ds.retl.dal.entity.Topology) TopologyVO(com.ds.retl.rest.vo.topology.TopologyVO)

Example 15 with EntityAccessException

use of org.mx.dal.exception.EntityAccessException in project main by JohnPeng739.

the class UserManageResource method getUser.

/**
 * 获取指定用户代码的用户信息
 *
 * @param userCode 用户代码
 * @return 用户信息对象
 */
@Path("users/{userCode}")
@GET
public DataVO<UserVO> getUser(@PathParam("userCode") String userCode) {
    try {
        User user = accessor.getByCode(userCode, User.class);
        if (user == null) {
            return new DataVO<>(new UserInterfaceErrorException(UserInterfaceErrors.USER_NOT_FOUND));
        }
        UserVO userVO = new UserVO();
        UserVO.transform(user, userVO);
        return new DataVO<>(userVO);
    } catch (EntityAccessException ex) {
        if (logger.isErrorEnabled()) {
            logger.error(ex);
        }
        return new DataVO<>(new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL));
    }
}
Also used : User(com.ds.retl.dal.entity.User) UserVO(com.ds.retl.rest.vo.user.UserVO) PaginationDataVO(org.mx.rest.vo.PaginationDataVO) DataVO(org.mx.rest.vo.DataVO) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException)

Aggregations

UserInterfaceErrorException (com.ds.retl.exception.UserInterfaceErrorException)15 EntityAccessException (org.mx.dal.exception.EntityAccessException)15 Transactional (org.springframework.transaction.annotation.Transactional)6 JSONObject (com.alibaba.fastjson.JSONObject)5 User (com.ds.retl.dal.entity.User)5 Topology (com.ds.retl.dal.entity.Topology)4 IOException (java.io.IOException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 EntityInstantiationException (org.mx.dal.exception.EntityInstantiationException)3 ConfigJson (com.ds.retl.dal.entity.ConfigJson)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 PrintStream (java.io.PrintStream)2 Date (java.util.Date)2 DataVO (org.mx.rest.vo.DataVO)2 PaginationDataVO (org.mx.rest.vo.PaginationDataVO)2 ETLTopologyBuilder (com.ds.retl.ETLTopologyBuilder)1 RETLStormCli (com.ds.retl.cli.RETLStormCli)1 TopologyVO (com.ds.retl.rest.vo.topology.TopologyVO)1 UserVO (com.ds.retl.rest.vo.user.UserVO)1