示例#1
0
  @DwrPermission(admin = true)
  public List<StringStringPair> versionCheck() {
    if (UPGRADE_DOWNLOADER != null) return UPGRADE_DOWNLOADER.getModules();

    try {
      // Create the request
      List<Module> modules = ModuleRegistry.getModules();
      Module.sortByName(modules);

      Map<String, Object> json = new HashMap<String, Object>();
      json.put("guid", Providers.get(ICoreLicense.class).getGuid());
      json.put("description", SystemSettingsDao.getValue(SystemSettingsDao.INSTANCE_DESCRIPTION));
      json.put("distributor", Common.envProps.getString("distributor"));
      json.put(
          "domain", ControllerUtils.getDomain(WebContextFactory.get().getHttpServletRequest()));

      Map<String, String> jsonModules = new HashMap<String, String>();
      json.put("modules", jsonModules);

      jsonModules.put("core", Common.getVersion().getFullString());
      for (Module module : modules) jsonModules.put(module.getName(), module.getVersion());

      StringWriter stringWriter = new StringWriter();
      new JsonWriter(Common.JSON_CONTEXT, stringWriter).writeObject(json);
      String requestData = stringWriter.toString();

      // Send the request
      String baseUrl = Common.envProps.getString("store.url");
      baseUrl += "/servlet/versionCheck";

      HttpPost post = new HttpPost(baseUrl);
      post.setEntity(new StringEntity(requestData));
      String responseData = HttpUtils4.getTextContent(Common.getHttpClient(), post);

      // Parse the response
      JsonTypeReader jsonReader = new JsonTypeReader(responseData);
      JsonObject root = jsonReader.read().toJsonObject();

      List<StringStringPair> upgrades = new ArrayList<StringStringPair>();
      for (Map.Entry<String, JsonValue> mod : root.entrySet()) {
        String name = mod.getKey();
        String version = mod.getValue().toString();
        upgrades.add(new StringStringPair(name, version));
      }

      return upgrades;
    } catch (Exception e) {
      throw new ShouldNeverHappenException(e);
    }
  }