Exemplo n.º 1
0
  @RequestMapping(
      value = {"/pumaServerSetting/delete"},
      method = RequestMethod.POST,
      produces = "application/json; charset=utf-8")
  @ResponseBody
  public String delete(String id) {
    Map<String, Object> map = new HashMap<String, Object>();
    try {
      if (id == null) {
        throw new IllegalArgumentException("id不能为空");
      }
      // 删除
      this.pumaServerConfigService.remove(new ObjectId(id));

      map.put("success", true);
    } catch (IllegalArgumentException e) {
      map.put("success", false);
      map.put("errorMsg", e.getMessage());
    } catch (Exception e) {
      map.put("success", false);
      map.put("errorMsg", e.getMessage());
      LOG.error(e.getMessage(), e);
    }
    return GsonUtil.toJson(map);
  }
Exemplo n.º 2
0
  @RequestMapping(
      value = {"/pumaServerSetting/create"},
      method = RequestMethod.POST,
      produces = "application/json; charset=utf-8")
  @ResponseBody
  public String createPost(String mysqlName, String[] host, String target) {
    Map<String, Object> map = new HashMap<String, Object>();
    try {
      if (StringUtils.isBlank(mysqlName)) {
        throw new IllegalArgumentException("mysqlName不能为空");
      }
      if (host == null || host.length <= 0) {
        throw new IllegalArgumentException("host不能为空");
      }
      if (StringUtils.isBlank(target)) {
        throw new IllegalArgumentException("target不能为空");
      }
      // 验证mysqlName是否存在
      if (mysqlConfigService.find(mysqlName) == null) {
        throw new IllegalArgumentException("不存在名称为" + mysqlName + "的数据库配置,如果需要请先添加!");
      }
      // 保存
      PumaServerConfig pumaServerConfig = new PumaServerConfig();
      pumaServerConfig.setMysqlName(mysqlName);
      pumaServerConfig.setHosts(Arrays.asList(host));
      pumaServerConfig.setTarget(target);
      this.pumaServerConfigService.save(pumaServerConfig);

      map.put("success", true);
    } catch (IllegalArgumentException e) {
      map.put("success", false);
      map.put("errorMsg", e.getMessage());
    } catch (Exception e) {
      map.put("success", false);
      map.put("errorMsg", e.getMessage());
      LOG.error(e.getMessage(), e);
    }
    return GsonUtil.toJson(map);
  }