use of org.mx.dal.exception.EntityInstantiationException in project main by JohnPeng739.
the class TopologyManageServiceImpl method save.
/**
* {@inheritDoc}
*
* @see TopologyManageService#save(String, String)
*/
@Transactional
@Override
public Topology save(String id, String topologyJsonStr) throws UserInterfaceErrorException {
try {
Topology topology;
if (StringUtils.isBlank(id)) {
topology = EntityFactory.createEntity(Topology.class);
} else {
topology = accessor.getById(id, Topology.class);
if (topology == null) {
throw new UserInterfaceErrorException(UserInterfaceErrors.TOPOLOGY_NOT_FOUND);
}
}
JSONObject json = JSON.parseObject(topologyJsonStr);
String name = json.getString("name");
topology.setName(name);
topology.setDescription(json.getString("description"));
topology.setSubmitted(false);
topology.setSubmitInfo("");
topology.setTopologyId(null);
topology.setTopologyContent(topologyJsonStr);
topology = accessor.save(topology);
operateLogService.writeLog(String.format("成功保存[%s]计算拓扑。", name));
return topology;
} catch (EntityAccessException | EntityInstantiationException ex) {
if (logger.isErrorEnabled()) {
logger.error(ex);
}
throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
}
}
use of org.mx.dal.exception.EntityInstantiationException in project main by JohnPeng739.
the class UserManageServiceImpl method initUser.
/**
* {@inheritDoc}
*
* @see UserManageService#initUser()
*/
@Transactional
@Override
public User initUser() throws UserInterfaceErrorException {
String userCode = "ds110";
try {
User user = accessor.getByCode(userCode, User.class);
if (user == null) {
user = EntityFactory.createEntity(User.class);
user.setCode("ds110");
}
try {
user.setPassword(DigestUtils.md5("edmund110119"));
} catch (NoSuchAlgorithmException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.USER_PASSWORD_DISGEST_FAIL);
}
user.setName("RETL管理员");
user.setRoles("manager");
return saveUser(user);
} catch (EntityInstantiationException | EntityAccessException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
}
}
use of org.mx.dal.exception.EntityInstantiationException in project main by JohnPeng739.
the class ServerManageServiceImpl method saveServerInfo.
/**
* {@inheritDoc}
*
* @see ServerManageService#saveServerInfo(String)
*/
@Override
public JSONObject saveServerInfo(String info) throws UserInterfaceErrorException {
if (StringUtils.isBlank(info)) {
throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
}
JSONObject json;
try {
json = JSON.parseObject(info);
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error(String.format("Parse json fail, %s.", info), ex);
}
throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
}
String machineName = json.getString("machineName"), machineIp = json.getString("machineIp");
if (StringUtils.isBlank(machineName)) {
if (logger.isErrorEnabled()) {
logger.error("The machine's name is blank.");
}
throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_ILLEGAL_PARAM);
}
try {
ConfigJson config = accessor.getByCode(createMachineConfigField(machineName), ConfigJson.class);
if (config == null) {
config = EntityFactory.createEntity(ConfigJson.class);
config.setCode(createMachineConfigField(machineName));
}
config.setConfigContent(info);
accessor.save(config);
config = accessor.getByCode(createMachineConfigField(machineName), ConfigJson.class);
if (config == null) {
throw new UserInterfaceErrorException(UserInterfaceErrors.SYSTEM_CONFIG_NOT_FOUND);
}
operateLogService.writeLog(String.format("保存服务器[name=%s, ip=%s]配置信息成功。", machineName, machineIp));
return JSON.parseObject(config.getConfigContent());
} catch (EntityAccessException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
} catch (EntityInstantiationException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.DB_ENTITY_INSTANCE_FAIL);
}
}
Aggregations