org.bson.BsonBoolean Java Examples
The following examples show how to use
org.bson.BsonBoolean.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TriggerEngine.java From epcis with Apache License 2.0 | 6 votes |
private static BsonValue converseType(String value) { String[] valArr = value.split("\\^"); if (valArr.length != 2) { return new BsonString(value); } try { String type = valArr[1]; if (type.equals("int")) { return new BsonInt32(Integer.parseInt(valArr[0])); } else if (type.equals("long")) { return new BsonInt64(Long.parseLong(valArr[0])); } else if (type.equals("double")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("boolean")) { return new BsonBoolean(Boolean.parseBoolean(valArr[0])); } else { return new BsonString(value); } } catch (NumberFormatException e) { return new BsonString(value); } }
Example #2
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 6 votes |
static BsonDocument getExistsQueryObject(String[] fieldArr, String str, BsonBoolean isExist) { BsonArray conjQueries = new BsonArray(); for (String field : fieldArr) { BsonDocument query = new BsonDocument(); if (str != null) { str = encodeMongoObjectKey(str); query.put(field + "." + str, new BsonDocument("$exists", isExist)); } else { query.put(field, new BsonDocument("$exists", isExist)); } conjQueries.add(query); } if (conjQueries.size() != 0) { BsonDocument queryObject = new BsonDocument(); if (isExist.equals(BsonBoolean.TRUE)) queryObject.put("$or", conjQueries); else { queryObject.put("$and", conjQueries); } return queryObject; } else { return null; } }
Example #3
Source File: TriggerEngine.java From epcis with Apache License 2.0 | 6 votes |
private static BsonValue converseType(String value) { String[] valArr = value.split("\\^"); if (valArr.length != 2) { return new BsonString(value); } try { String type = valArr[1]; if (type.equals("int")) { return new BsonInt32(Integer.parseInt(valArr[0])); } else if (type.equals("long")) { return new BsonInt64(Long.parseLong(valArr[0])); } else if (type.equals("double")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("boolean")) { return new BsonBoolean(Boolean.parseBoolean(valArr[0])); } else { return new BsonString(value); } } catch (NumberFormatException e) { return new BsonString(value); } }
Example #4
Source File: SubscriptionType.java From epcis with Apache License 2.0 | 6 votes |
public static BsonDocument asBsonDocument(SubscriptionType subscription) { BsonDocument bson = new BsonDocument(); if (subscription.getSubscriptionID() != null) { bson.put("subscriptionID", new BsonString(subscription.getSubscriptionID())); } if (subscription.getDest() != null) { bson.put("dest", new BsonString(subscription.getDest())); } if (subscription.getSchedule() != null) { bson.put("schedule", new BsonString(subscription.getSchedule())); } if (subscription.getTrigger() != null) { bson.put("trigger", new BsonString(subscription.getTrigger())); } if (subscription.getInitialRecordTime() != null) { bson.put("initialRecordTime", new BsonString(subscription.getInitialRecordTime())); } bson.put("reportIfEmpty", new BsonBoolean(subscription.getReportIfEmpty())); bson.put("pollParameters", PollParameters.asBsonDocument(subscription.getPollParameters())); return bson; }
Example #5
Source File: UpdateDescription.java From stitch-android-sdk with Apache License 2.0 | 6 votes |
/** * Convert this update description to an update document. * * @return an update document with the appropriate $set and $unset documents. */ public BsonDocument toUpdateDocument() { final List<BsonElement> unsets = new ArrayList<>(); for (final String removedField : this.removedFields) { unsets.add(new BsonElement(removedField, new BsonBoolean(true))); } final BsonDocument updateDocument = new BsonDocument(); if (this.updatedFields.size() > 0) { updateDocument.append("$set", this.updatedFields); } if (unsets.size() > 0) { updateDocument.append("$unset", new BsonDocument(unsets)); } return updateDocument; }
Example #6
Source File: ChronoElement.java From epcis with Apache License 2.0 | 6 votes |
/** * @param timestamp * @param projection * @return TimestampProperties BsonDocument only containing projection keys */ public BsonDocument getTimestampProperties(final Long timestamp, final String[] projection) { BsonDocument bsonProjection = new BsonDocument(); if (projection != null) { for (String string : projection) { bsonProjection.append(string, new BsonBoolean(true)); } } if (this instanceof ChronoVertex) return graph.getVertexEvents().find(new BsonDocument(Tokens.VERTEX, new BsonString(this.id)) .append(Tokens.TIMESTAMP, new BsonDateTime(timestamp))).projection(bsonProjection).first(); else return graph.getEdgeCollection() .find(new BsonDocument(Tokens.ID, new BsonString(this.id + "-" + timestamp))) .projection(bsonProjection).first(); }
Example #7
Source File: CoreDocumentSynchronizationConfig.java From stitch-android-sdk with Apache License 2.0 | 6 votes |
/** * A document that is paused no longer has remote updates applied to it. * Any local updates to this document cause it to be thawed. An example of pausing a document * is when a conflict is being resolved for that document and the handler throws an exception. * * @param isPaused whether or not this config is frozen */ void setPaused(final boolean isPaused) { docLock.writeLock().lock(); try { docsColl.updateOne( getDocFilter(namespace, documentId), new BsonDocument("$set", new BsonDocument( ConfigCodec.Fields.IS_PAUSED, new BsonBoolean(isPaused)))); this.isPaused = isPaused; } catch (IllegalStateException e) { // eat this } finally { docLock.writeLock().unlock(); } }
Example #8
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 6 votes |
static BsonDocument getExistsQueryObject(String[] fieldArr, String str, BsonBoolean isExist) { BsonArray conjQueries = new BsonArray(); for (String field : fieldArr) { BsonDocument query = new BsonDocument(); if (str != null) { str = encodeMongoObjectKey(str); query.put(field + "." + str, new BsonDocument("$exists", isExist)); } else { query.put(field, new BsonDocument("$exists", isExist)); } conjQueries.add(query); } if (conjQueries.size() != 0) { BsonDocument queryObject = new BsonDocument(); if (isExist.equals(BsonBoolean.TRUE)) queryObject.put("$or", conjQueries); else { queryObject.put("$and", conjQueries); } return queryObject; } else { return null; } }
Example #9
Source File: SubscriptionType.java From epcis with Apache License 2.0 | 6 votes |
public static BsonDocument asBsonDocument(SubscriptionType subscription) { BsonDocument bson = new BsonDocument(); if (subscription.getSubscriptionID() != null) { bson.put("subscriptionID", new BsonString(subscription.getSubscriptionID())); } if (subscription.getDest() != null) { bson.put("dest", new BsonString(subscription.getDest())); } if (subscription.getSchedule() != null) { bson.put("schedule", new BsonString(subscription.getSchedule())); } if (subscription.getTrigger() != null) { bson.put("trigger", new BsonString(subscription.getTrigger())); } if (subscription.getInitialRecordTime() != null) { bson.put("initialRecordTime", new BsonString(subscription.getInitialRecordTime())); } bson.put("reportIfEmpty", new BsonBoolean(subscription.getReportIfEmpty())); bson.put("pollParameters", PollParameters.asBsonDocument(subscription.getPollParameters())); return bson; }
Example #10
Source File: CompactChangeEvent.java From stitch-android-sdk with Apache License 2.0 | 6 votes |
/** * Serializes this change event into a {@link BsonDocument}. * @return the serialized document. */ public BsonDocument toBsonDocument() { final BsonDocument asDoc = new BsonDocument(); asDoc.put(Fields.OPERATION_TYPE_FIELD, new BsonString(getOperationType().toRemote())); asDoc.put(Fields.DOCUMENT_KEY_FIELD, getDocumentKey()); if (getFullDocument() != null && (getFullDocument() instanceof BsonValue) && ((BsonValue) getFullDocument()).isDocument()) { asDoc.put(Fields.FULL_DOCUMENT_FIELD, (BsonValue) getFullDocument()); } if (getUpdateDescription() != null) { asDoc.put(Fields.UPDATE_DESCRIPTION_FIELD, getUpdateDescription().toBsonDocument()); } if (stitchDocumentVersion != null) { asDoc.put(Fields.STITCH_DOCUMENT_VERSION_FIELD, stitchDocumentVersion.toBsonDocument()); } if (stitchDocumentHash != null) { asDoc.put(Fields.STITCH_DOCUMENT_HASH_FIELD, new BsonInt64(stitchDocumentHash)); } asDoc.put(Fields.WRITE_PENDING_FIELD, new BsonBoolean(hasUncommittedWrites())); return asDoc; }
Example #11
Source File: DeserialisationTest.java From octarine with Apache License 2.0 | 6 votes |
@Test public void deserialise_boolean() { Key<Boolean> booleanKey = Key.named("my-value"); BsonRecordDeserialiser deserialiser = BsonRecordDeserialiser.builder() .readBoolean(booleanKey) .get(); BsonDocument trueDoc = new BsonDocument(); trueDoc.put("my-value", new BsonBoolean(true)); Record trueRecord = deserialiser.apply(trueDoc); assertTrue("wasn't true", booleanKey.get(trueRecord).get()); BsonDocument falseDoc = new BsonDocument(); falseDoc.put("my-value", new BsonBoolean(false)); Record falseRecord = Record.of(booleanKey.of(false)); assertFalse("wasn't false", booleanKey.get(falseRecord).get()); }
Example #12
Source File: VertexEvent.java From epcis with Apache License 2.0 | 5 votes |
public Set<VertexEvent> getInVertexEventSet(final String label, final AC tt) { // db.edges.createIndex({"_outV" : 1, "_label" : 1, "_t" : 1, "_inV" : 1}) BsonDocument query = new BsonDocument(Tokens.IN_VERTEX, new BsonString(vertex.toString())); query.append(Tokens.LABEL, new BsonString(label)); query.append(Tokens.TIMESTAMP, new BsonDocument(tt.toString(), new BsonDateTime(timestamp))); BsonDocument proj = new BsonDocument(Tokens.TIMESTAMP, new BsonBoolean(true)) .append(Tokens.OUT_VERTEX, new BsonBoolean(true)).append(Tokens.ID, new BsonBoolean(false)); HashSet<VertexEvent> ret = new HashSet<VertexEvent>(); Iterator<BsonDocument> x = vertex.graph.getEdgeCollection().find(query).projection(proj).iterator(); HashMap<String, Long> map = new HashMap<String, Long>(); while (x.hasNext()) { BsonDocument d = x.next(); String outV = d.getString(Tokens.OUT_VERTEX).getValue(); Long t = d.getDateTime(Tokens.TIMESTAMP).getValue(); if (map.containsKey(outV)) { if (map.get(outV) > t) map.put(outV, t); } else map.put(outV, t); } map.entrySet().parallelStream().forEach(entry -> { VertexEvent ve = new VertexEvent(graph, entry.getKey() + "-" + entry.getValue()); ret.add(ve); }); return ret; }
Example #13
Source File: TypeConversionTest.java From immutables with Apache License 2.0 | 5 votes |
@Test void booleanValue() throws IOException { check(Parsers.parserAt(new BsonBoolean(true)).getCurrentToken()).is(JsonToken.VALUE_TRUE); check(Parsers.parserAt(new BsonBoolean(false)).getCurrentToken()).is(JsonToken.VALUE_FALSE); check(Parsers.parserAt(new BsonBoolean(true)).getText()).is("true"); check(Parsers.parserAt(new BsonBoolean(false)).getText()).is("false"); check(Parsers.parserAt(new BsonBoolean(true)).getBooleanValue()); check(!Parsers.parserAt(new BsonBoolean(false)).getBooleanValue()); }
Example #14
Source File: ECReportCapture.java From epcis with Apache License 2.0 | 5 votes |
private Map<String, BsonValue> getExtensionMap(List<ECReportMemberField> fields) { Map<String, BsonValue> extMap = new HashMap<String, BsonValue>(); for (int l = 0; l < fields.size(); l++) { ECReportMemberField field = fields.get(l); String key = field.getName(); String value = field.getValue(); String[] valArr = value.split("\\^"); if (valArr.length != 2) { extMap.put(key, new BsonString(value)); continue; } try { String type = valArr[1]; if (type.equals("int")) { extMap.put(key, new BsonInt32(Integer.parseInt(valArr[0]))); } else if (type.equals("long")) { extMap.put(key, new BsonInt64(Long.parseLong(valArr[0]))); } else if (type.equals("double")) { extMap.put(key, new BsonDouble(Double.parseDouble(valArr[0]))); } else if (type.equals("boolean")) { extMap.put(key, new BsonBoolean(Boolean.parseBoolean(valArr[0]))); } else if (type.equals("dateTime")) { extMap.put(key, new BsonDateTime(Long.parseLong(valArr[0]))); } else { extMap.put(key, new BsonString(valArr[0])); } } catch (NumberFormatException e) { extMap.put(key, new BsonString(valArr[0])); } } return extMap; }
Example #15
Source File: TypeConversionTest.java From immutables with Apache License 2.0 | 5 votes |
@Test void parseExceptions() { Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonBoolean(true)).getNumberValue(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonBoolean(true)).getLongValue(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(BsonNull.VALUE).getNumberValue(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(BsonNull.VALUE).getNumberType(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonInt32(42)).getBooleanValue(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonBoolean(true)).getNumberType(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonDateTime(42)).getBooleanValue(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonTimestamp(42)).getBooleanValue(); }); }
Example #16
Source File: MongoCaptureUtil.java From epcis with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") private BsonDocument makeOtherwiseIdenticalFilter(BsonDocument filter) { filter.remove("errorDeclaration"); filter.put("errorDeclaration", new BsonDocument("$exists", new BsonBoolean(false))); filter.remove("recordTime"); return filter; }
Example #17
Source File: BsonReaderTest.java From immutables with Apache License 2.0 | 5 votes |
/** * Reading from BSON to GSON */ @Test public void bsonToGson() throws Exception { BsonDocument document = new BsonDocument(); document.append("boolean", new BsonBoolean(true)); document.append("int32", new BsonInt32(32)); document.append("int64", new BsonInt64(64)); document.append("double", new BsonDouble(42.42D)); document.append("string", new BsonString("foo")); document.append("null", new BsonNull()); document.append("array", new BsonArray()); document.append("object", new BsonDocument()); JsonElement element = TypeAdapters.JSON_ELEMENT.read(new BsonReader(new BsonDocumentReader(document))); check(element.isJsonObject()); check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().isBoolean()); check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().getAsBoolean()); check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().isNumber()); check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().getAsNumber().intValue()).is(32); check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().isNumber()); check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().getAsNumber().longValue()).is(64L); check(element.getAsJsonObject().get("double").getAsJsonPrimitive().isNumber()); check(element.getAsJsonObject().get("double").getAsJsonPrimitive().getAsNumber().doubleValue()).is(42.42D); check(element.getAsJsonObject().get("string").getAsJsonPrimitive().isString()); check(element.getAsJsonObject().get("string").getAsJsonPrimitive().getAsString()).is("foo"); check(element.getAsJsonObject().get("null").isJsonNull()); check(element.getAsJsonObject().get("array").isJsonArray()); check(element.getAsJsonObject().get("object").isJsonObject()); }
Example #18
Source File: ChronoElement.java From epcis with Apache License 2.0 | 5 votes |
/** * Return the object value associated with the provided string key. If no value * exists for that key, return null. * * @param key the key of the key/value property, Tokens.ID, Tokens.LABEL, * Tokens.OUT_VERTEX, Tokens.IN_VERTEX included * @return the object value related to the string key */ @Override public <T> T getProperty(final String key) { BsonDocument doc = null; if (this instanceof ChronoVertex) { doc = graph.getVertexCollection().find(new BsonDocument(Tokens.ID, new BsonString(this.id))) .projection(new BsonDocument(key, new BsonBoolean(true))).first(); } else { doc = graph.getEdgeCollection().find(new BsonDocument(Tokens.ID, new BsonString(this.id))) .projection(new BsonDocument(key, new BsonBoolean(true))).first(); } if (doc != null) return (T) doc.get(key); return null; }
Example #19
Source File: TypeConversionTest.java From immutables with Apache License 2.0 | 5 votes |
@Test public void bsonBoolean() throws IOException { check(Jsons.readerAt(new BsonBoolean(true)).peek()).is(JsonToken.BOOLEAN); check(Jsons.readerAt(new BsonBoolean(false)).peek()).is(JsonToken.BOOLEAN); check(Jsons.readerAt(new BsonBoolean(true)).nextBoolean()); check(!Jsons.readerAt(new BsonBoolean(false)).nextBoolean()); }
Example #20
Source File: VertexEvent.java From epcis with Apache License 2.0 | 5 votes |
public Set<VertexEvent> getOutVertexEventSet(final String label, final AC tt) { // db.edges.createIndex({"_outV" : 1, "_label" : 1, "_t" : 1, "_inV" : 1}) BsonDocument query = new BsonDocument(Tokens.OUT_VERTEX, new BsonString(vertex.toString())); query.append(Tokens.LABEL, new BsonString(label)); query.append(Tokens.TIMESTAMP, new BsonDocument(tt.toString(), new BsonDateTime(timestamp))); BsonDocument proj = new BsonDocument(Tokens.TIMESTAMP, new BsonBoolean(true)) .append(Tokens.IN_VERTEX, new BsonBoolean(true)).append(Tokens.ID, new BsonBoolean(false)); HashSet<VertexEvent> ret = new HashSet<VertexEvent>(); Iterator<BsonDocument> x = vertex.graph.getEdgeEvents().find(query).projection(proj).iterator(); HashMap<String, Long> map = new HashMap<String, Long>(); while (x.hasNext()) { BsonDocument d = x.next(); String inV = d.getString(Tokens.IN_VERTEX).getValue(); Long t = d.getDateTime(Tokens.TIMESTAMP).getValue(); if (map.containsKey(inV)) { if (map.get(inV) > t) map.put(inV, t); } else map.put(inV, t); } map.entrySet().parallelStream().forEach(entry -> { VertexEvent ve = new VertexEvent(graph, entry.getKey() + "-" + entry.getValue()); ret.add(ve); }); return ret; }
Example #21
Source File: VertexEvent.java From epcis with Apache License 2.0 | 5 votes |
public Set<VertexEvent> getOutVertexEventSet(final AC tt) { while (true) { try { // db.tEdgeEvents.aggregate([{$match:{"_o":"1","_t":{ $lt : ISODate(0) // }}},{$project:{"_i":1,"_t":1,"_id":0}},{$group:{"_id":"$_i", "_mt": {$min: // "$_t"}}}]) BsonDocument match = new BsonDocument("$match", new BsonDocument(Tokens.OUT_VERTEX, new BsonString(vertex.toString())).append(Tokens.TIMESTAMP, new BsonDocument("$gt", new BsonDateTime(timestamp)))); BsonDocument project = new BsonDocument("$project", new BsonDocument(Tokens.IN_VERTEX, new BsonBoolean(true)) .append(Tokens.TIMESTAMP, new BsonBoolean(true)) .append(Tokens.ID, new BsonBoolean(false))); BsonDocument group = new BsonDocument("$group", new BsonDocument(Tokens.ID, new BsonString("$" + Tokens.IN_VERTEX)).append(Tokens.TIMESTAMP, new BsonDocument("$min", new BsonString("$" + Tokens.TIMESTAMP)))); ArrayList<BsonDocument> aggregateQuery = new ArrayList<BsonDocument>(); aggregateQuery.add(match); aggregateQuery.add(project); aggregateQuery.add(group); HashSet<VertexEvent> ret = new HashSet<VertexEvent>(); Function<BsonDocument, VertexEvent> mapper = new Function<BsonDocument, VertexEvent>() { @Override public VertexEvent apply(BsonDocument d) { String inV = d.getString(Tokens.ID).getValue(); Long t = d.getDateTime(Tokens.TIMESTAMP).getValue(); return new VertexEvent(graph, new ChronoVertex(inV, graph), t); } }; vertex.graph.getEdgeEvents().aggregate(aggregateQuery).map(mapper).into(ret); return ret; } catch (MongoCursorNotFoundException e1) { System.out.println(e1.getErrorMessage()); } } }
Example #22
Source File: MongoWriterUtil.java From epcis with Apache License 2.0 | 5 votes |
public static BsonValue converseType(String value) { String[] valArr = value.split("\\^"); if (valArr.length != 2) { return new BsonString(value); } try { String type = valArr[1]; if (type.equals("int")) { return new BsonInt32(Integer.parseInt(valArr[0])); } else if (type.equals("long")) { return new BsonInt64(Long.parseLong(valArr[0])); } else if (type.equals("double")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("boolean")) { return new BsonBoolean(Boolean.parseBoolean(valArr[0])); } else if (type.equals("float")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("dateTime")) { BsonDateTime time = getBsonDateTime(valArr[0]); if (time != null) return time; return new BsonString(value); } else if (type.equals("geoPoint")) { BsonDocument point = getBsonGeoPoint(valArr[0]); if (point == null) return new BsonString(value); return point; } else if (type.equals("geoArea")) { BsonDocument area = getBsonGeoArea(valArr[0]); if (area == null) return new BsonString(value); return area; } else { return new BsonString(value); } } catch (NumberFormatException e) { return new BsonString(value); } }
Example #23
Source File: SinkDocumentTest.java From mongo-kafka with Apache License 2.0 | 5 votes |
@BeforeAll static void initBsonDocs() { flatStructKey = new BsonDocument(); flatStructKey.put("_id", new BsonObjectId(ObjectId.get())); flatStructKey.put("myBoolean", new BsonBoolean(true)); flatStructKey.put("myInt", new BsonInt32(42)); flatStructKey.put("myBytes", new BsonBinary(new byte[] {65, 66, 67})); BsonArray ba1 = new BsonArray(); ba1.addAll(asList(new BsonInt32(1), new BsonInt32(2), new BsonInt32(3))); flatStructKey.put("myArray", ba1); flatStructValue = new BsonDocument(); flatStructValue.put("myLong", new BsonInt64(42L)); flatStructValue.put("myDouble", new BsonDouble(23.23d)); flatStructValue.put("myString", new BsonString("BSON")); flatStructValue.put("myBytes", new BsonBinary(new byte[] {120, 121, 122})); BsonArray ba2 = new BsonArray(); ba2.addAll(asList(new BsonInt32(9), new BsonInt32(8), new BsonInt32(7))); flatStructValue.put("myArray", ba2); nestedStructKey = new BsonDocument(); nestedStructKey.put("_id", new BsonDocument("myString", new BsonString("doc"))); nestedStructKey.put( "mySubDoc", new BsonDocument("mySubSubDoc", new BsonDocument("myInt", new BsonInt32(23)))); nestedStructValue = new BsonDocument(); nestedStructValue.put("mySubDocA", new BsonDocument("myBoolean", new BsonBoolean(false))); nestedStructValue.put( "mySubDocB", new BsonDocument( "mySubSubDocC", new BsonDocument("myString", new BsonString("some text...")))); }
Example #24
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 5 votes |
static BsonValue converseType(String value) { String[] valArr = value.split("\\^"); if (valArr.length != 2) { return new BsonString(value); } try { String type = valArr[1].trim(); if (type.equals("int")) { return new BsonInt32(Integer.parseInt(valArr[0])); } else if (type.equals("long")) { return new BsonInt64(Long.parseLong(valArr[0])); } else if (type.equals("double")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("boolean")) { return new BsonBoolean(Boolean.parseBoolean(valArr[0])); } else if (type.equals("regex")) { return new BsonRegularExpression("^" + valArr[0] + "$"); } else if (type.equals("float")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("dateTime")) { BsonDateTime time = MongoQueryService.getTimeMillis(valArr[0]); if (time != null) return time; return new BsonString(value); } else { return new BsonString(value); } } catch (NumberFormatException e) { return new BsonString(value); } }
Example #25
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 5 votes |
static BsonDocument getExistsQueryObject(String field, String str, BsonBoolean isExist) { BsonDocument query = new BsonDocument(); if (str != null) { str = encodeMongoObjectKey(str); query.put(field + "." + str, new BsonDocument("$exists", isExist)); } else { query.put(field, new BsonDocument("$exists", isExist)); } return query; }
Example #26
Source File: MongoCaptureUtil.java From epcis with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") private BsonDocument makeOtherwiseIdenticalFilter(BsonDocument filter) { filter.remove("errorDeclaration"); filter.put("errorDeclaration", new BsonDocument("$exists", new BsonBoolean(false))); filter.remove("recordTime"); return filter; }
Example #27
Source File: ECReportCapture.java From epcis with Apache License 2.0 | 5 votes |
private Map<String, BsonValue> getExtensionMap(List<ECReportMemberField> fields) { Map<String, BsonValue> extMap = new HashMap<String, BsonValue>(); for (int l = 0; l < fields.size(); l++) { ECReportMemberField field = fields.get(l); String key = field.getName(); String value = field.getValue(); String[] valArr = value.split("\\^"); if (valArr.length != 2) { extMap.put(key, new BsonString(value)); continue; } try { String type = valArr[1]; if (type.equals("int")) { extMap.put(key, new BsonInt32(Integer.parseInt(valArr[0]))); } else if (type.equals("long")) { extMap.put(key, new BsonInt64(Long.parseLong(valArr[0]))); } else if (type.equals("double")) { extMap.put(key, new BsonDouble(Double.parseDouble(valArr[0]))); } else if (type.equals("boolean")) { extMap.put(key, new BsonBoolean(Boolean.parseBoolean(valArr[0]))); } else if (type.equals("dateTime")) { extMap.put(key, new BsonDateTime(Long.parseLong(valArr[0]))); } else { extMap.put(key, new BsonString(valArr[0])); } } catch (NumberFormatException e) { extMap.put(key, new BsonString(valArr[0])); } } return extMap; }
Example #28
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 5 votes |
static BsonValue converseType(String value) { String[] valArr = value.split("\\^"); if (valArr.length != 2) { return new BsonString(value); } try { String type = valArr[1].trim(); if (type.equals("int")) { return new BsonInt32(Integer.parseInt(valArr[0])); } else if (type.equals("long")) { return new BsonInt64(Long.parseLong(valArr[0])); } else if (type.equals("double")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("boolean")) { return new BsonBoolean(Boolean.parseBoolean(valArr[0])); } else if (type.equals("regex")) { return new BsonRegularExpression("^" + valArr[0] + "$"); } else if (type.equals("float")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("dateTime")) { BsonDateTime time = MongoQueryService.getTimeMillis(valArr[0]); if (time != null) return time; return new BsonString(value); } else { return new BsonString(value); } } catch (NumberFormatException e) { return new BsonString(value); } }
Example #29
Source File: SinkFieldConverterTest.java From mongo-kafka with Apache License 2.0 | 5 votes |
@TestFactory @DisplayName("tests for boolean field conversions") List<DynamicTest> testBooleanFieldConverter() { SinkFieldConverter converter = new BooleanFieldConverter(); List<DynamicTest> tests = new ArrayList<>(); asList(true, false) .forEach( el -> tests.add( dynamicTest( "conversion with " + converter.getClass().getSimpleName() + " for " + el, () -> assertEquals(el, ((BsonBoolean) converter.toBson(el)).getValue())))); tests.add( dynamicTest( "optional type conversion checks", () -> { Schema valueOptionalDefault = SchemaBuilder.bool().optional().defaultValue(true); assertAll( "", () -> assertThrows( DataException.class, () -> converter.toBson(null, Schema.BOOLEAN_SCHEMA)), () -> assertEquals( new BsonNull(), converter.toBson(null, Schema.OPTIONAL_BOOLEAN_SCHEMA)), () -> assertEquals( valueOptionalDefault.defaultValue(), converter.toBson(null, valueOptionalDefault).asBoolean().getValue())); })); return tests; }
Example #30
Source File: RdbmsDeleteTest.java From kafka-connect-mongodb with Apache License 2.0 | 5 votes |
@Test @DisplayName("when valid cdc event without PK then correct DeleteOneModel") public void testValidSinkDocumentNoPK() { BsonDocument filterDoc = new BsonDocument("text", new BsonString("hohoho")) .append("number", new BsonInt32(9876)) .append("active", new BsonBoolean(true)); BsonDocument keyDoc = new BsonDocument(); BsonDocument valueDoc = new BsonDocument("op",new BsonString("c")) .append("before",new BsonDocument("text", new BsonString("hohoho")) .append("number", new BsonInt32(9876)) .append("active", new BsonBoolean(true))); WriteModel<BsonDocument> result = RDBMS_DELETE.perform(new SinkDocument(keyDoc,valueDoc)); assertTrue(result instanceof DeleteOneModel, () -> "result expected to be of type DeleteOneModel"); DeleteOneModel<BsonDocument> writeModel = (DeleteOneModel<BsonDocument>) result; assertTrue(writeModel.getFilter() instanceof BsonDocument, () -> "filter expected to be of type BsonDocument"); assertEquals(filterDoc,writeModel.getFilter()); }