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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations