/** * Returns true if the value of the key is a BsonObjectId, returns false if the document does not contain the key. * * @param key the key * @return true if the value of the key is a BsonObjectId, returns false if the document does not contain the key. */ public boolean isObjectId(final Object key) { if (!containsKey(key)) { return false; } return get(key).isObjectId(); }
@Override public ObjectId getObjectId() { if (!fileId.isObjectId()) { throw new MongoGridFSException("Custom id type used for this GridFS upload stream"); } return fileId.asObjectId().getValue(); }
/** * The {@link ObjectId} for this file. * * Throws a MongoGridFSException if the file id is not an ObjectId. * * @return the id for this file. */ public ObjectId getObjectId() { if (!id.isObjectId()) { throw new MongoGridFSException("Custom id type used for this GridFS file"); } return id.asObjectId().getValue(); }
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"); } }
@Override public ObjectId getObjectId() { if (!fileId.isObjectId()) { throw new MongoGridFSException("Custom id type used for this GridFS upload stream"); } return fileId.asObjectId().getValue(); }
@Override public ObjectId getObjectId() { if (!fileId.isObjectId()) { throw new MongoGridFSException("Custom id type used for this GridFS upload stream"); } return fileId.asObjectId().getValue(); }
/** * The {@link ObjectId} for this file. * * Throws a MongoGridFSException if the file id is not an ObjectId. * * @return the id for this file. */ public ObjectId getObjectId() { if (!id.isObjectId()) { throw new MongoGridFSException("Custom id type used for this GridFS file"); } return id.asObjectId().getValue(); }
return o.get().isBoolean(); case "objectid": return o.get().isObjectId(); case "objectidstring": return o.get().isString()
private void _transform(BsonDocument data) { data.keySet().stream().forEach(key -> { BsonValue value = data.get(key); if (value.isDocument()) { _transform(value.asDocument()); } else if (value.isObjectId()) { data.put(key, new BsonString(value .asObjectId() .getValue() .toString())); } }); } }
.concat("/") .concat(docId.asString().getValue()); } else if (docId.isObjectId()) { uri = URLUtils.removeTrailingSlashes(parentUrl) .concat("/")
private static void embeddedDocuments( List<BsonDocument> embeddedData, String requestPath, Representation rep, boolean isHalFull) { embeddedData.stream().forEach((d) -> { BsonValue _id = d.get("_id"); if (_id != null && (_id.isString() || _id.isObjectId())) { Representation nrep = new Representation(); if (isHalFull) { nrep.addProperty("_type", new BsonString(RequestContext.TYPE.INDEX.name())); } nrep.addProperties(d); rep.addRepresentation("rh:index", nrep); } else { rep.addWarning("index with _id " + _id + (_id == null ? " " : " of type " + _id.getBsonType().name()) + "filtered out. Indexes can only " + "have ids of type String"); LOGGER.debug("index missing string _id field", d); } }); }
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("\"", "'")); } }
/** * * @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); } }
/** * * @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()); } }
BsonDocument filter = rom.getFilter().toBsonDocument(BsonDocument.class,null); assertEquals(1,filter.size(),"filter document should only contain "+DBCollection.ID_FIELD_NAME); assertTrue(filter.get(DBCollection.ID_FIELD_NAME).isObjectId(),"filter document _id was not of type ObjectId"); assertTrue(rom.getReplacement().get(DBCollection.ID_FIELD_NAME).isObjectId(),"replacement document _id was not of type ObjectId"); assertEquals(42,rom.getReplacement().getInt32("myValueField").getValue(),"myValueField's value mismatch");
return translateObject(value.asDocument()); if (value.isObjectId()) { ObjectId id = value.asObjectId().getValue(); byte[] bsonBytes = id.toByteArray();