Search in sources :

Example 26 with UserInterfaceErrorException

use of com.ds.retl.exception.UserInterfaceErrorException in project main by JohnPeng739.

the class TopologyManageServiceImpl method validateJmsDataSource.

/**
 * {@inheritDoc}
 *
 * @see TopologyManageService#validateJmsDataSource(String)
 */
@Override
public boolean validateJmsDataSource(String resourceJsonStr) throws UserInterfaceErrorException {
    if (logger.isDebugEnabled()) {
        logger.debug("Start validate the JMS server ...");
    }
    JSONObject json = JSON.parseObject(resourceJsonStr);
    String protocol = json.getString("protocol"), server = json.getString("server"), user = json.getString("user"), password = json.getString("password"), method = json.getString("method");
    boolean trace = json.getBooleanValue("trace");
    String connStr = String.format("%s%s?trace=%s", protocol, server, trace ? "true" : "false");
    if ("ACTIVEMQ".equals(method)) {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug(String.format("validate JMS connection: %s.", connStr));
            }
            ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(user, password, connStr);
            javax.jms.Connection conn = factory.createConnection();
            conn.getClientID();
            conn.close();
            if (logger.isDebugEnabled()) {
                logger.debug("Validate the JMS server successfully.");
            }
            return true;
        } catch (JMSException ex) {
            if (logger.isErrorEnabled()) {
                logger.error(ex);
            }
            throw new UserInterfaceErrorException(UserInterfaceErrors.TOPOLOGY_VALIDATE_FAIL);
        }
    } else {
        if (logger.isErrorEnabled()) {
            logger.error(String.format("Not supported type: %s.", method));
        }
        throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) JSONObject(com.alibaba.fastjson.JSONObject) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) JMSException(javax.jms.JMSException)

Example 27 with UserInterfaceErrorException

use of com.ds.retl.exception.UserInterfaceErrorException 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 28 with UserInterfaceErrorException

use of com.ds.retl.exception.UserInterfaceErrorException 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 29 with UserInterfaceErrorException

use of com.ds.retl.exception.UserInterfaceErrorException 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 30 with UserInterfaceErrorException

use of com.ds.retl.exception.UserInterfaceErrorException in project main by JohnPeng739.

the class ServerManageResource method getServers.

@Path("servers")
@POST
public PaginationDataVO<List<ServerInfoVO>> getServers(Pagination pagination) {
    if (pagination == null) {
        pagination = new Pagination();
    }
    try {
        Map<String, JSONObject> map = serverManageService.getServerInfos(pagination);
        List<ServerInfoVO> list = new ArrayList<>();
        map.values().forEach(json -> list.add(new ServerInfoVO(json)));
        return new PaginationDataVO<>(pagination, list);
    } catch (UserInterfaceErrorException ex) {
        return new PaginationDataVO<>(ex);
    }
}
Also used : Pagination(org.mx.dal.Pagination) PaginationDataVO(org.mx.rest.vo.PaginationDataVO) JSONObject(com.alibaba.fastjson.JSONObject) ServerInfoVO(com.ds.retl.rest.vo.server.ServerInfoVO) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) ArrayList(java.util.ArrayList)

Aggregations

UserInterfaceErrorException (com.ds.retl.exception.UserInterfaceErrorException)35 JSONObject (com.alibaba.fastjson.JSONObject)17 EntityAccessException (org.mx.dal.exception.EntityAccessException)15 PaginationDataVO (org.mx.rest.vo.PaginationDataVO)13 DataVO (org.mx.rest.vo.DataVO)12 Topology (com.ds.retl.dal.entity.Topology)8 User (com.ds.retl.dal.entity.User)7 Transactional (org.springframework.transaction.annotation.Transactional)6 TopologyVO (com.ds.retl.rest.vo.topology.TopologyVO)5 ServerInfoVO (com.ds.retl.rest.vo.server.ServerInfoVO)3 UserVO (com.ds.retl.rest.vo.user.UserVO)3 IOException (java.io.IOException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 EntityInstantiationException (org.mx.dal.exception.EntityInstantiationException)3 RestInvokeException (org.mx.rest.client.RestInvokeException)3 JSONArray (com.alibaba.fastjson.JSONArray)2 ConfigJson (com.ds.retl.dal.entity.ConfigJson)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 PrintStream (java.io.PrintStream)2