/** * @return this object as a {@link JsonObject} */ public JsonObject toJsonObject() { JsonObject r = super.toJsonObject(); if (parentFieldName != null) { r.put("parentName", parentFieldName); } return r; } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (getClass() != obj.getClass()) { return false; } XMLChunkMeta other = (XMLChunkMeta)obj; if (parents == null) { if (other.parents != null) { return false; } } else if (!parents.equals(other.parents)) { return false; } return true; }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((parents == null) ? 0 : parents.hashCode()); return result; }
/** * Create a {@link XMLChunkMeta} object. Sub-classes may override this * method to provide their own {@link XMLChunkMeta} type. * @param hit the chunk meta content used to initialize the object * @return the created object */ protected ChunkMeta createChunkMeta(JsonObject hit) { String mimeType = hit.getString("mimeType", XMLChunkMeta.MIME_TYPE); if (belongsTo(mimeType, "application", "xml") || belongsTo(mimeType, "text", "xml")) { return new XMLChunkMeta(hit); } else if (belongsTo(mimeType, "application", "geo+json")) { return new GeoJsonChunkMeta(hit); } else if (belongsTo(mimeType, "application", "json")) { return new JsonChunkMeta(hit); } return new ChunkMeta(hit); } }
private Completable ensureMerger(ChunkMeta meta) { if (meta instanceof XMLChunkMeta) { if (xmlMerger == null) { if (geoJsonMerger != null) { return Completable.error(new IllegalStateException("Cannot merge " + "XML chunk into a GeoJSON document.")); } xmlMerger = new XMLMerger(optimistic); } return Completable.complete(); } else if (meta instanceof GeoJsonChunkMeta) { if (geoJsonMerger == null) { if (xmlMerger != null) { return Completable.error(new IllegalStateException("Cannot merge " + "GeoJSON chunk into an XML document.")); } geoJsonMerger = new GeoJsonMerger(optimistic); } return Completable.complete(); } return Completable.error(new IllegalStateException("Cannot merge " + "chunk of type " + meta.getMimeType())); }
/** * Convert a {@link JsonObject} to a {@link ChunkMeta} object * @param source the JSON object to convert * @return the converted object */ private ChunkMeta getMeta(JsonObject source) { String mimeType = source.getString("mimeType", XMLChunkMeta.MIME_TYPE); if (belongsTo(mimeType, "application", "xml") || belongsTo(mimeType, "text", "xml")) { return new XMLChunkMeta(source); } else if (belongsTo(mimeType, "application", "geo+json")) { return new GeoJsonChunkMeta(source); } else if (belongsTo(mimeType, "application", "json")) { return new JsonChunkMeta(source); } else { return new ChunkMeta(source); } }
String mimeType = chunkMeta.getMimeType(); if (belongsTo(mimeType, "application", "xml") || belongsTo(mimeType, "text", "xml")) {
/** * @return this object as a {@link JsonObject} */ public JsonObject toJsonObject() { JsonArray ps = new JsonArray(); parents.forEach(p -> ps.add(p.toJsonObject())); return super.toJsonObject() .put("parents", ps); } }
@Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((parentFieldName == null) ? 0 : parentFieldName.hashCode()); return result; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (getClass() != obj.getClass()) { return false; } JsonChunkMeta other = (JsonChunkMeta)obj; if (parentFieldName == null) { if (other.parentFieldName != null) { return false; } } else if (!parentFieldName.equals(other.parentFieldName)) { return false; } return true; }
@Override public void onIndexChunk(String path, ChunkMeta chunkMeta, IndexMeta indexMeta) { result.put("path", path); result.put("chunkMeta", chunkMeta.toJsonObject()); if (indexMeta.getTags() != null) { result.put("tags", indexMeta.getTags()); } if (indexMeta.getProperties() != null) { result.put("props", indexMeta.getProperties()); } if (indexMeta.getCorrelationId() != null) { result.put("correlationId", indexMeta.getCorrelationId()); } } }
.put("meta", chunkMeta.toJsonObject());
JsonObject jsonMeta = source.getJsonObject("chunkMeta"); ChunkMeta meta = getMeta(jsonMeta); JsonObject obj = meta.toJsonObject() .put("id", id); resultHits.add(obj);