Esempio n. 1
0
 public void deleteOwner(Owner owner) {
   List<Override> overrides =
       overrideService.findByServiceAndAddress(owner.getService(), Constants.ANYHOST_VALUE);
   if (overrides == null || overrides.size() == 0) {
     Override override = new Override();
     override.setAddress(Constants.ANYHOST_VALUE);
     override.setService(owner.getService());
     override.setEnabled(true);
     override.setParams("owner=" + owner.getUsername());
     overrideService.saveOverride(override);
   } else {
     for (Override override : overrides) {
       Map<String, String> params = StringUtils.parseQueryString(override.getParams());
       String usernames = params.get("owner");
       if (usernames != null && usernames.length() > 0) {
         if (usernames.equals(owner.getUsername())) {
           params.remove("owner");
         } else {
           usernames =
               usernames
                   .replace(owner.getUsername() + ",", "")
                   .replace("," + owner.getUsername(), "");
           params.put("owner", usernames);
         }
         if (params.size() > 0) {
           override.setParams(StringUtils.toQueryString(params));
           overrideService.updateOverride(override);
         } else {
           overrideService.deleteOverride(override.getId());
         }
       }
     }
   }
 }
Esempio n. 2
0
  public void disableProvider(Long id) {
    if (id == null) {
      throw new IllegalStateException("no provider id");
    }

    Provider oldProvider = findProvider(id);
    if (oldProvider == null) {
      throw new IllegalStateException("Provider was changed!");
    }

    if (oldProvider.isDynamic()) {
      // 保证disable的override唯一
      if (oldProvider.isEnabled()) {
        Override override = new Override();
        override.setAddress(oldProvider.getAddress());
        override.setService(oldProvider.getService());
        override.setEnabled(true);
        override.setParams(Constants.DISABLED_KEY + "=true");
        overrideService.saveOverride(override);
        return;
      }
      List<Override> oList =
          overrideService.findByServiceAndAddress(
              oldProvider.getService(), oldProvider.getAddress());

      for (Override o : oList) {
        Map<String, String> params = StringUtils.parseQueryString(o.getParams());
        if (params.containsKey(Constants.DISABLED_KEY)) {
          if (params.get(Constants.DISABLED_KEY).equals("false")) {
            overrideService.deleteOverride(o.getId());
          }
        }
      }
    } else {
      oldProvider.setEnabled(false);
      updateProvider(oldProvider);
    }
  }