Exemplo n.º 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);
    }
  }
Exemplo n.º 2
0
 public static void jsonWriteVarContext(ObjectWriter writer, List<IntStringPair> context)
     throws IOException, JsonException {
   DataPointDao dataPointDao = new DataPointDao();
   JsonArray pointList = new JsonArray();
   for (IntStringPair p : context) {
     DataPointVO dp = dataPointDao.getDataPoint(p.getKey());
     if (dp != null) {
       JsonObject point = new JsonObject();
       pointList.add(point);
       point.put("varName", new JsonString(p.getValue()));
       point.put("dataPointXid", new JsonString(dp.getXid()));
     }
   }
   writer.writeEntry("context", pointList);
 }
Exemplo n.º 3
0
  public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    DataPointDao dataPointDao = new DataPointDao();
    String xid = jsonObject.getString("dataPointId");
    if (xid == null)
      throw new TranslatableJsonException("emport.error.publishedPoint.missing", "dataPointId");

    DataPointVO vo = dataPointDao.getDataPoint(xid);
    if (vo == null) throw new TranslatableJsonException("emport.error.missingPoint", xid);
    dataPointId = vo.getId();
  }
Exemplo n.º 4
0
  public static void jsonReadVarContext(JsonObject json, List<IntStringPair> context)
      throws JsonException {
    JsonArray jsonContext = json.getJsonArray("context");
    if (jsonContext != null) {
      context.clear();
      DataPointDao dataPointDao = new DataPointDao();

      for (JsonValue jv : jsonContext) {
        JsonObject jo = jv.toJsonObject();
        String xid = jo.getString("dataPointXid");
        if (xid == null)
          throw new TranslatableJsonException("emport.error.meta.missing", "dataPointXid");

        DataPointVO dp = dataPointDao.getDataPoint(xid);
        if (dp == null) throw new TranslatableJsonException("emport.error.missingPoint", xid);

        String var = jo.getString("varName");
        if (var == null)
          throw new TranslatableJsonException("emport.error.meta.missing", "varName");

        context.add(new IntStringPair(dp.getId(), var));
      }
    }
  }
Exemplo n.º 5
0
  @Override
  public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    String text = jsonObject.getString("loggingType");
    if (text != null) {
      loggingType = LOGGING_TYPE_CODES.getId(text);
      if (loggingType == -1)
        throw new TranslatableJsonException(
            "emport.error.invalid", "loggingType", text, LOGGING_TYPE_CODES.getCodeList());
    }

    text = jsonObject.getString("intervalLoggingPeriodType");
    if (text != null) {
      intervalLoggingPeriodType = Common.TIME_PERIOD_CODES.getId(text);
      if (intervalLoggingPeriodType == -1)
        throw new TranslatableJsonException(
            "emport.error.invalid",
            "intervalLoggingPeriodType",
            text,
            Common.TIME_PERIOD_CODES.getCodeList());
    }

    text = jsonObject.getString("intervalLoggingType");
    if (text != null) {
      intervalLoggingType = INTERVAL_LOGGING_TYPE_CODES.getId(text);
      if (intervalLoggingType == -1)
        throw new TranslatableJsonException(
            "emport.error.invalid",
            "intervalLoggingType",
            text,
            INTERVAL_LOGGING_TYPE_CODES.getCodeList());
    }

    text = jsonObject.getString("purgeType");
    if (text != null) {
      purgeType = Common.TIME_PERIOD_CODES.getId(text);
      if (purgeType == -1)
        throw new TranslatableJsonException(
            "emport.error.invalid", "purgeType", text, Common.TIME_PERIOD_CODES.getCodeList());
    }

    JsonObject locatorJson = jsonObject.getJsonObject("pointLocator");
    if (locatorJson != null) reader.readInto(pointLocator, locatorJson);

    JsonArray pedArray = jsonObject.getJsonArray("eventDetectors");
    if (pedArray != null) {
      for (JsonValue jv : pedArray) {
        JsonObject pedObject = jv.toJsonObject();

        String pedXid = pedObject.getString("xid");
        if (StringUtils.isBlank(pedXid))
          throw new TranslatableJsonException("emport.error.ped.missingAttr", "xid");

        // Use the ped xid to lookup an existing ped.
        PointEventDetectorVO ped = null;
        for (PointEventDetectorVO existing : eventDetectors) {
          if (StringUtils.equals(pedXid, existing.getXid())) {
            ped = existing;
            break;
          }
        }

        if (ped == null) {
          // Create a new one
          ped = new PointEventDetectorVO();
          ped.setId(Common.NEW_ID);
          ped.setXid(pedXid);
          ped.njbSetDataPoint(this);
          eventDetectors.add(ped);
        }

        reader.readInto(ped, pedObject);
      }
    }

    text = jsonObject.getString("engineeringUnits");
    if (text != null) {
      engineeringUnits = ENGINEERING_UNITS_CODES.getId(text);
      if (engineeringUnits == -1) engineeringUnits = ENGINEERING_UNITS_DEFAULT;
    }

    text = jsonObject.getString("plotType");
    if (text != null) {
      plotType = PLOT_TYPE_CODES.getId(text);
      if (plotType == -1)
        throw new TranslatableJsonException(
            "emport.error.invalid", "plotType", text, PLOT_TYPE_CODES.getCodeList());
    }
  }