Exemplo n.º 1
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.º 2
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.º 3
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());
    }
  }