예제 #1
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();
  }
예제 #2
0
 protected void writeProperty(JsonGenerator jg, Property prop) throws IOException {
   if (prop.isScalar()) {
     writeScalarProperty(jg, prop);
   } else if (prop.isList()) {
     writeListProperty(jg, prop);
   } else {
     if (prop.isPhantom()) {
       jg.writeNull();
     } else if (prop instanceof BlobProperty) { // a blob
       writeBlobProperty(jg, prop);
     } else { // a complex property
       writeComplexProperty(jg, prop);
     }
   }
 }
예제 #3
0
 private void writeScalarPropertyValue(JsonGenerator jg, Type type, Object value)
     throws IOException {
   if (value == null) {
     jg.writeNull();
   } else if (type instanceof BooleanType) {
     jg.writeBoolean((Boolean) value);
   } else if (type instanceof LongType) {
     jg.writeNumber((Long) value);
   } else if (type instanceof DoubleType) {
     jg.writeNumber((Double) value);
   } else if (type instanceof IntegerType) {
     jg.writeNumber((Integer) value);
   } else if (type instanceof BinaryType) {
     jg.writeBinary((byte[]) value);
   } else {
     jg.writeString(type.encode(value));
   }
 }
예제 #4
0
  protected void writeBlobProperty(JsonGenerator jg, Property prop) throws IOException {
    Blob blob = (Blob) prop.getValue();
    if (blob == null) {
      jg.writeNull();
      return;
    }
    jg.writeStartObject();
    String v = blob.getFilename();
    if (v == null) {
      jg.writeNullField("name");
    } else {
      jg.writeStringField("name", v);
    }
    v = blob.getMimeType();
    if (v == null) {
      jg.writeNullField("mime-type");
    } else {
      jg.writeStringField("mime-type", v);
    }
    v = blob.getEncoding();
    if (v == null) {
      jg.writeNullField("encoding");
    } else {
      jg.writeStringField("encoding", v);
    }
    v = blob.getDigest();
    if (v == null) {
      jg.writeNullField("digest");
    } else {
      jg.writeStringField("digest", v);
    }
    jg.writeStringField("length", Long.toString(blob.getLength()));

    String blobUrl = getBlobUrl(prop);
    if (blobUrl == null) {
      blobUrl = "";
    }
    jg.writeStringField("data", blobUrl);
    jg.writeEndObject();
  }