Exemplo n.º 1
0
  /**
   * This method writes the state of the NodeManager to disk
   *
   * @param jsonGenerator The instance of JsonGenerator, which will be used to write JSON to disk
   * @throws IOException
   */
  public void write(JsonGenerator jsonGenerator) throws IOException {
    jsonGenerator.writeStartObject();

    // nameToNode begins
    jsonGenerator.writeFieldName("nameToNode");
    jsonGenerator.writeStartObject();
    for (Map.Entry<String, ClusterNode> entry : nameToNode.entrySet()) {
      jsonGenerator.writeFieldName(entry.getKey());
      entry.getValue().write(jsonGenerator);
    }
    jsonGenerator.writeEndObject();
    // nameToNode ends

    // hostsToSessions begins
    // We create a new Map of type <ClusterNode.name, Set<SessionIds>>.
    // The original hostsToSessions map has the ClusterNode as its key, and
    // we do not need to persist the entire ClusterNode again, since we have
    // already done that with nameToNode.
    Map<String, Set<String>> hostsToSessionsMap = new HashMap<String, Set<String>>();
    for (Map.Entry<ClusterNode, Set<String>> entry : hostsToSessions.entrySet()) {
      hostsToSessionsMap.put(entry.getKey().getName(), entry.getValue());
    }
    jsonGenerator.writeObjectField("hostsToSessions", hostsToSessionsMap);
    // hostsToSessions ends

    jsonGenerator.writeObjectField("nameToApps", nameToApps);

    // faultManager is not required

    // We can rebuild the loadManager
    jsonGenerator.writeEndObject();
  }
    @Override
    public void serialize(
        SimpleEvaluationObject value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {

      synchronized (value) {
        String id = getUpdateManager().register(value);
        jgen.writeStartObject();
        jgen.writeObjectField("type", "SimpleEvaluationObject");
        jgen.writeStringField("update_id", id);
        jgen.writeStringField("expression", value.getExpression());
        jgen.writeObjectField("status", value.getStatus());
        if (value.getMessage() != null) jgen.writeStringField("message", value.getMessage());
        if (value.getProgressBar() > 0)
          jgen.writeNumberField("progressBar", value.getProgressBar());
        if (value.getPayloadChanged()) {
          EvaluationResult o = value.getPayload();
          if (o != null && o.getValue() != null) {
            jgen.writeFieldName("payload");
            if (!getObjectSerializer().writeObject(o, jgen, true)) jgen.writeObject(o.toString());
          } else if (value.getJsonRes() != null) {
            jgen.writeFieldName("payload");
            if (ControlCharacterUtils.containsControlCharacters(value.getJsonRes())) {
              jgen.writeRawValue(ControlCharacterUtils.escapeControlCharacters(value.getJsonRes()));
            } else {
              jgen.writeRawValue(value.getJsonRes());
            }
          }
        }
        if (value.getJsonRes() != null
            && value.getPayload() != null
            && value.getPayload().getValue() != null) {
          logger.trace("adding raw json data: '" + value.getJsonRes() + "'");
          jgen.writeFieldName("jsonres");
          if (ControlCharacterUtils.containsControlCharacters(value.getJsonRes())) {
            jgen.writeRawValue(ControlCharacterUtils.escapeControlCharacters(value.getJsonRes()));
          } else {
            jgen.writeRawValue(value.getJsonRes());
          }
        }
        jgen.writeArrayFieldStart("outputdata");
        for (Object o : value.getOutputdata()) {
          if (o instanceof EvaluationStdOutput) {
            jgen.writeStartObject();
            jgen.writeStringField("type", "out");
            jgen.writeStringField("value", ((EvaluationStdOutput) o).payload);
            jgen.writeEndObject();
          } else if (o instanceof EvaluationStdError) {
            jgen.writeStartObject();
            jgen.writeStringField("type", "err");
            jgen.writeStringField("value", ((EvaluationStdError) o).payload);
            jgen.writeEndObject();
          }
        }
        jgen.writeEndArray();
        jgen.writeEndObject();
      }
    }
  @Override
  public void serialize(T value, JsonGenerator jgen, SerializerProvider provider)
      throws IOException, JsonProcessingException {

    synchronized (value) {
      jgen.writeStartObject();
      jgen.writeObjectField("type", value.getClass().getSimpleName());
      jgen.writeObjectField("borderDisplayed", value.isBorderDisplayed());
      serialize(value, jgen);
      jgen.writeEndObject();
    }
  }
 @Override
 public void serialize(
     OpenExternalURLAction value, JsonGenerator jgen, SerializerProvider provider)
     throws IOException {
   jgen.writeStartObject();
   try {
     jgen.writeObjectField("type", "url");
     jgen.writeObjectField("content", value.getValue().toString());
   } finally {
     jgen.writeEndObject();
   }
 }
Exemplo n.º 5
0
    @Override
    public void serialize(TableDisplay value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {

      synchronized (value) {
        jgen.writeStartObject();
        jgen.writeObjectField("type", "TableDisplay");
        jgen.writeObjectField("columnNames", value.columns);
        jgen.writeObjectField("values", value.values);
        // jgen.writeObjectField("timeZone", "UTC");
        jgen.writeEndObject();
      }
    }
 @Override
 public void serialize(RichPushMessage message, JsonGenerator jgen, SerializerProvider provider)
     throws IOException {
   jgen.writeStartObject();
   jgen.writeStringField("title", message.getTitle());
   jgen.writeStringField("body", message.getBody());
   jgen.writeStringField("content_type", message.getContentType());
   jgen.writeStringField("content_encoding", message.getContentEncoding());
   if (message.getExpiry().isPresent()) {
     jgen.writeObjectField("expiry", message.getExpiry().get());
   }
   if (message.getExtra().isPresent()) {
     jgen.writeObjectField("extra", message.getExtra().get());
   }
   jgen.writeEndObject();
 }
 @Override
 protected void writeSubclassFields(final JsonGenerator jgen, final DatePickerComponent component)
     throws IOException {
   if (component.getShowTime() != null) {
     jgen.writeObjectField("showTime", component.getShowTime().toString());
   }
 }
  @Override
  public void serialize(Area area, JsonGenerator jgen, SerializerProvider sp)
      throws IOException, JsonProcessingException {

    jgen.writeStartObject();

    super.serialize(area, jgen, sp);

    jgen.writeObjectField("type", area.getClass().getSimpleName());
    if (area.getColor() instanceof Color) {
      jgen.writeObjectField("color", area.getColor());
    }
    if (area.getInterpolation() != null) {
      jgen.writeObjectField("interpolation", area.getInterpolation());
    }
    jgen.writeEndObject();
  }
Exemplo n.º 9
0
  void toJson(JsonGenerator gen) throws IOException {
    gen.writeStartObject();
    gen.writeArrayFieldStart("sourceSchemas");
    for (Schema schema : schemas) {
      schema.toJson(gen);
    }
    gen.writeEndArray();
    gen.writeObjectFieldStart("fieldAliases");
    for (Map.Entry<String, Map<String, String>> entry : schemaFieldAliases.entrySet()) {
      String schemaName = entry.getKey();
      Map<String, String> aliases = entry.getValue();
      gen.writeObjectField(schemaName, aliases);
    }
    gen.writeEndObject();

    gen.writeArrayFieldStart("groupByFields");
    for (String field : groupByFields) {
      gen.writeString(field);
    }
    gen.writeEndArray();

    if (customPartitionFields != null && !customPartitionFields.isEmpty()) {
      gen.writeArrayFieldStart("customPartitionFields");
      for (String field : customPartitionFields) {
        gen.writeString(field);
      }
      gen.writeEndArray();
    }

    if (rollupFrom != null) {
      gen.writeFieldName("rollupFrom");
      gen.writeString(rollupFrom);
    }

    gen.writeFieldName("commonOrderBy");
    commonCriteria.toJson(gen);

    gen.writeStringField("schemasOrder", schemasOrder.toString());

    // TODO this code should write a map with sourceName
    if (specificCriterias == null || specificCriterias.isEmpty()) {
      initSecondaryCriteriasWithNull();
    }
    gen.writeArrayFieldStart("specificOrderBys");
    for (Criteria c : specificCriterias) {
      if (c == null) {
        gen.writeNull();
      } else {
        c.toJson(gen);
      }
    }
    gen.writeEndArray();
    gen.writeEndObject();
  }
Exemplo n.º 10
0
  @Override
  public void writeTo(
      Object object,
      Class<?> type,
      Type genericType,
      Annotation[] annotations,
      MediaType mediaType,
      MultivaluedMap<String, Object> httpHeaders,
      OutputStream entityStream)
      throws IOException, WebApplicationException {
    JsonGenerator writer = null;
    if (type.isAssignableFrom(ArtifactReadable.class)) {
      ArtifactReadable artifact = (ArtifactReadable) object;
      try {
        writer = jsonFactory.createJsonGenerator(entityStream);
        //         writer.setPrettyPrinter(new DefaultPr)
        writer.writeStartObject();
        writer.writeNumberField("uuid", artifact.getLocalId());
        if (matches(IdentityView.class, annotations)) {
          writer.writeStringField("Name", artifact.getName());
        } else {
          AttributeTypes attributeTypes = getAttibuteTypes();
          Collection<? extends IAttributeType> attrTypes = attributeTypes.getAll();
          ResultSet<? extends AttributeReadable<Object>> attributes = artifact.getAttributes();
          if (!attributes.isEmpty()) {
            for (IAttributeType attrType : attrTypes) {
              if (artifact.isAttributeTypeValid(attrType)) {
                List<Object> attributeValues = artifact.getAttributeValues(attrType);
                if (!attributeValues.isEmpty()) {

                  if (attributeValues.size() > 1) {
                    writer.writeArrayFieldStart(attrType.getName());
                    for (Object value : attributeValues) {
                      writer.writeObject(value);
                    }
                    writer.writeEndArray();
                  } else if (attributeValues.size() == 1) {
                    Object value = attributeValues.iterator().next();
                    writer.writeObjectField(attrType.getName(), value);
                  }
                }
              }
            }
          }
        }
        writer.writeEndObject();
      } finally {
        if (writer != null) {
          writer.flush();
        }
      }
    }
  }
  protected void serialize(T graphics, JsonGenerator jgen) throws IOException {

    jgen.writeObjectField("type", graphics.getClass().getSimpleName());

    jgen.writeObjectField("visible", graphics.getVisible());
    jgen.writeObjectField("yAxis", graphics.getYAxis());
    jgen.writeObjectField("showItemLabel", graphics.getShowItemLabel());
    jgen.writeObjectField("center_series", graphics.getCenterSeries());
    jgen.writeObjectField("use_tool_tip", graphics.getUseToolTip());

    if (graphics.getSeriesNames() != null) {
      jgen.writeObjectField("seriesNames", graphics.getSeriesNames());
    }
    if (graphics.getValue() != null) {
      jgen.writeObjectField("value", graphics.getValue());
    }
    if (graphics.getColors() != null) {
      jgen.writeObjectField("colors", graphics.getColors());
    } else {
      jgen.writeObjectField("color", graphics.getColor());
    }
  }