Search in sources :

Example 1 with EntityInstantiationException

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);
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) Topology(com.ds.retl.dal.entity.Topology) EntityInstantiationException(org.mx.dal.exception.EntityInstantiationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with EntityInstantiationException

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);
    }
}
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) EntityInstantiationException(org.mx.dal.exception.EntityInstantiationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with EntityInstantiationException

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);
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) ConfigJson(com.ds.retl.dal.entity.ConfigJson) EntityAccessException(org.mx.dal.exception.EntityAccessException) EntityInstantiationException(org.mx.dal.exception.EntityInstantiationException) EntityAccessException(org.mx.dal.exception.EntityAccessException) EntityInstantiationException(org.mx.dal.exception.EntityInstantiationException) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) IOException(java.io.IOException) RestInvokeException(org.mx.rest.client.RestInvokeException)

Aggregations

UserInterfaceErrorException (com.ds.retl.exception.UserInterfaceErrorException)3 EntityAccessException (org.mx.dal.exception.EntityAccessException)3 EntityInstantiationException (org.mx.dal.exception.EntityInstantiationException)3 JSONObject (com.alibaba.fastjson.JSONObject)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ConfigJson (com.ds.retl.dal.entity.ConfigJson)1 Topology (com.ds.retl.dal.entity.Topology)1 User (com.ds.retl.dal.entity.User)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 RestInvokeException (org.mx.rest.client.RestInvokeException)1