AggregateOperationImpl<T> hint(final BsonValue hint) { isTrueArgument("BsonString or BsonDocument", hint == null || hint.isDocument() || hint.isString()); this.hint = hint; return this; }
/** * Returns true if the value of the key is a BsonString, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonString, returns false if the document does not contain the key. */ public boolean isString(final Object key) { if (!containsKey(key)) { return false; } return get(key).isString(); }
/** * Sets the hint for which index to use. A null value means no hint is set. * * @param hint the hint * @return this * @since 3.6 * @mongodb.server.release 3.6 */ public AggregateExplainOperation hint(final BsonValue hint) { isTrueArgument("BsonString or BsonDocument", hint == null || hint.isDocument() || hint.isString()); this.hint = hint; return this; }
public SchemaStoreURL(String schemaDb, BsonValue schemaId) { Objects.requireNonNull(schemaDb); Objects.requireNonNull(schemaId); if (schemaId.isString() || schemaId.isObjectId()) { this.schemaDb = schemaDb; this.schemaId = schemaId; } else { throw new IllegalArgumentException( "schemaId must be a String or an ObjectId"); } }
/** * Sets the hint for which index to use. A null value means no hint is set. * * @param hint the hint * @return this * @since 3.6 * @mongodb.server.release 3.6 */ public AggregateExplainOperation hint(final BsonValue hint) { isTrueArgument("BsonString or BsonDocument", hint == null || hint.isDocument() || hint.isString()); this.hint = hint; return this; }
AggregateOperationImpl<T> hint(final BsonValue hint) { isTrueArgument("BsonString or BsonDocument", hint == null || hint.isDocument() || hint.isString()); this.hint = hint; return this; }
private static String getIdString(BsonValue id) throws UnsupportedDocumentIdException { if (id == null) { return null; } else if (id.isString()) { return "'" + id.asString().getValue() + "'"; } else { return JsonUtils.minify(JsonUtils.toJson(id) .replace("\"", "'")); } }
private String valueAsString(BsonValue value) { if (value.isDouble()) { return Double.toString(value.asDouble().getValue()); } else if (value.isString()) { return value.asString().getValue(); } else if (value.isInt64()) { return Long.toString(value.asInt64().getValue()); } else if (value.isInt32()) { return Long.toString(value.asInt32().getValue()); } else { return value.toString(); } }
private String extractFilenameFromProperties( final BsonDocument properties) { String filename = null; if (properties != null && properties.containsKey(FILENAME)) { BsonValue _filename = properties.get(FILENAME); if (_filename != null && _filename.isString()) { filename = _filename.asString().getValue(); } } if (filename == null) { return "file"; } else { return filename; } }
public QueryResult<String> distinct(String key, Bson query) { long start = startQuery(); List<String> l = new ArrayList<>(); MongoCursor<BsonValue> iterator = mongoDBNativeQuery.distinct(key, query, BsonValue.class).iterator(); while (iterator.hasNext()) { BsonValue value = iterator.next(); if (value == null || value.isNull()) { l.add(null); } else if (value.isString()) { l.add(value.asString().getValue()); } else { throw new IllegalArgumentException("Found result with BsonType != " + BsonType.STRING + " : " + value.getBsonType()); } } return endQuery(l, start); }
BsonValue _name = props.get(RT_NAME_ELEMENT_NAME); BsonValue _args = props.get(RT_ARGS_ELEMENT_NAME); if (_phase == null || !_phase.isString()) { throw new InvalidMetadataException((_phase == null ? "missing '" : "invalid '") + RT_PHASE_ELEMENT_NAME + "' element; acceptable values are: " + Arrays.toString(PHASE.values())); if (_scope == null || !_scope.isString()) { throw new InvalidMetadataException("invalid '" + RT_SCOPE_ELEMENT_NAME + "' element; acceptable values are: " + Arrays.toString(SCOPE.values())); if (_name == null || !_name.isString()) { throw new InvalidMetadataException((_name == null ? "missing '" : "invalid '") + RT_NAME_ELEMENT_NAME + "' element");
private static HookMetadata getSingleFromJson(BsonDocument props) throws InvalidMetadataException { BsonValue _name = props.get(NAME_KEY); if (_name == null || !(_name.isString())) { throw new InvalidMetadataException( (_name == null ? "missing '" : "invalid '") + NAME_KEY + "' element. it must be of type String"); } String name = _name.asString().getValue(); // args is optional return new HookMetadata(name, props.get(ARGS_KEY)); }
private static String getIdAsStringNoBrachets(BsonValue id) throws UnsupportedDocumentIdException { if (id == null) { return null; } else if (id.isString()) { return id.asString().getValue(); } else if (id.isObjectId()) { return id.asObjectId().getValue().toHexString(); } else { return JsonUtils.minify( JsonUtils.toJson(id)); } }
/** * * @param id * @param quote * @return the String representation of the id */ public static String getIdAsString(BsonValue id, boolean quote) { if (id == null) { return null; } else if (id.isString()) { return quote ? "'" + id.asString().getValue() + "'" : id.asString().getValue(); } else if (id.isObjectId()) { return id.asObjectId().getValue().toString(); } else { return JsonUtils.minify(JsonUtils.toJson(id) .replace("\"", "'")); } }
private void _transform(BsonDocument data, Set<String> propertiesNames) { data.keySet().stream().forEach(key -> { BsonValue value = data.get(key); if (shouldTransform(key, propertiesNames)) { if (value.isString() && ObjectId.isValid(value .asString() .getValue())) { data.put(key, new BsonObjectId( new ObjectId(value .asString() .getValue()))); } } if (value instanceof BsonDocument) { _transform(value.asDocument(), propertiesNames); } }); }
/** * * @param exchange * @param etag */ public static void injectEtagHeader( HttpServerExchange exchange, Object etag) { if (etag == null) { return; } if (etag instanceof BsonValue) { BsonValue _etag = (BsonValue) etag; if (_etag.isObjectId()) { setETagHeader(exchange, _etag.asObjectId().getValue().toString()); } else if (_etag.isString()) { setETagHeader(exchange, _etag.asString().getValue()); } } else if (etag instanceof ObjectId) { setETagHeader(exchange, etag.toString()); } else if (etag instanceof String) { setETagHeader(exchange, (String) etag); } }
public CdcOperation getCdcOperation(BsonDocument doc) { try { if(!doc.containsKey(OPERATION_TYPE_FIELD_PATH) || !doc.get(OPERATION_TYPE_FIELD_PATH).isString()) { throw new DataException("error: value doc is missing CDC operation type of type string"); } CdcOperation op = operations.get(OperationType.fromText( doc.get(OPERATION_TYPE_FIELD_PATH).asString().getValue()) ); if(op == null) { throw new DataException("error: no CDC operation found in mapping for op=" + doc.get(OPERATION_TYPE_FIELD_PATH).asString().getValue()); } return op; } catch (IllegalArgumentException exc){ throw new DataException("error: parsing CDC operation failed",exc); } }
public CdcOperation getCdcOperation(BsonDocument doc) { try { if(!doc.containsKey(OPERATION_TYPE_FIELD_PATH) || !doc.get(OPERATION_TYPE_FIELD_PATH).isString()) { throw new DataException("error: value doc is missing CDC operation type of type string"); } CdcOperation op = operations.get(OperationType.fromText( doc.get(OPERATION_TYPE_FIELD_PATH).asString().getValue()) ); if(op == null) { throw new DataException("error: no CDC operation found in mapping for op=" + doc.get(OPERATION_TYPE_FIELD_PATH).asString().getValue()); } return op; } catch (IllegalArgumentException exc){ throw new DataException("error: parsing CDC operation failed",exc); } }
/** * * @param exchange * @param properties */ public static void injectEtagHeader( HttpServerExchange exchange, BsonDocument properties) { if (properties == null) { return; } BsonValue _etag = properties.get("_etag"); if (_etag == null) { return; } if (_etag.isObjectId()) { setETagHeader(exchange, _etag.asObjectId().getValue().toString()); } else if (_etag.isString()) { setETagHeader(exchange, _etag.asString().getValue()); } }
private static JsonValue mapBsonValueToJsonValue(@Nullable final BsonValue bsonValue, final Function<String, String> jsonKeyNameReviser) { final JsonValue result; if (bsonValue == null || bsonValue.isNull()) { result = JsonFactory.nullLiteral(); } else if (bsonValue.isString()) { result = JsonFactory.newValue(bsonValue.asString().getValue()); } else if (bsonValue.isNumber()) { result = mapBsonNumberToJsonNumber(bsonValue.asNumber()); } else if (bsonValue.isDocument()) { result = mapBsonDocumentToJsonObject(bsonValue.asDocument(), jsonKeyNameReviser); } else if (bsonValue.isArray()) { result = mapBsonArrayToJsonArray(bsonValue.asArray(), jsonKeyNameReviser); } else if (bsonValue.isBoolean()) { result = JsonFactory.newValue(bsonValue.asBoolean().getValue()); } else if (bsonValue.isTimestamp()) { final Instant instant = Instant.ofEpochSecond(bsonValue.asTimestamp().getTime()); result = JsonFactory.newValue(instant.toString()); } else { result = JsonFactory.nullLiteral(); } return result; }