Java Code Examples for org.bson.BsonArray#isEmpty()

The following examples show how to use org.bson.BsonArray#isEmpty() . 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: MongoQueryUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
static BsonDocument getFamilyQueryObject(String type, String[] fieldArr, String csv) {

		BsonArray orQueries = new BsonArray();
		for (String field : fieldArr) {
			String[] paramValueArr = csv.split("\\|");
			BsonArray subObjectList = new BsonArray();
			for (int i = 0; i < paramValueArr.length; i++) {
				String val = paramValueArr[i].trim();
				BsonDocument dbo = new BsonDocument();
				dbo.put(type, new BsonString(val));
				subObjectList.add(dbo);
			}
			if (subObjectList.isEmpty() == false) {
				BsonDocument query = new BsonDocument();
				query.put(field, new BsonDocument("$in", subObjectList));
				orQueries.add(query);
			}
		}
		if (orQueries.size() != 0) {
			BsonDocument queryObject = new BsonDocument();
			queryObject.put("$or", orQueries);
			return queryObject;
		} else {
			return null;
		}
	}
 
Example 2
Source File: ObjectEventWriteConverter.java    From epcis with Apache License 2.0 6 votes vote down vote up
public void capture(BsonObjectId dataID, Long eventTime, Set<String> epcList, BsonArray epcQuantities,
		String readPoint, String bizLocation, BsonArray sourceList, BsonArray destinationList) {

	ChronoGraph pg = Configuration.persistentGraph;

	if (epcList != null && !epcList.isEmpty()) {
		epcList.stream().forEach(object -> {
			MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, object, readPoint, bizLocation, sourceList,
					destinationList);
			pg.addTimestampVertexProperty(object, eventTime, "data", dataID);
		});
	}

	if (epcQuantities != null && !epcQuantities.isEmpty()) {
		epcQuantities.stream().forEach(classElem -> {
			MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, classElem, readPoint, bizLocation,
					sourceList, destinationList);
			pg.addTimestampVertexProperty(classElem.asDocument().getString("epcClass").getValue(), eventTime,
					"data", dataID);
		});
	}
	return;
}
 
Example 3
Source File: TransactionEventWriteConverter.java    From epcis with Apache License 2.0 6 votes vote down vote up
public void capture(BsonObjectId dataID, Long eventTime, Set<String> epcList, BsonArray epcQuantities,
		String readPoint, String bizLocation, BsonArray sourceList, BsonArray destinationList) {

	ChronoGraph pg = Configuration.persistentGraph;

	if (epcList != null && !epcList.isEmpty()) {
		epcList.stream().forEach(object -> {
			MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, object, readPoint, bizLocation, sourceList,
					destinationList);
			pg.addTimestampVertexProperty(object, eventTime, "data", dataID);
		});
	}

	if (epcQuantities != null && !epcQuantities.isEmpty()) {
		epcQuantities.stream().forEach(classElem -> {
			MongoWriterUtil.addBasicTimestampProperties(pg, eventTime, classElem, readPoint, bizLocation,
					sourceList, destinationList);
			pg.addTimestampVertexProperty(classElem.asDocument().getString("epcClass").getValue(), eventTime,
					"data", dataID);
		});
	}
}
 
Example 4
Source File: MongoQueryUtil.java    From epcis with Apache License 2.0 6 votes vote down vote up
static BsonDocument getFamilyQueryObject(String type, String[] fieldArr, String csv) {

		BsonArray orQueries = new BsonArray();
		for (String field : fieldArr) {
			String[] paramValueArr = csv.split("\\|");
			BsonArray subObjectList = new BsonArray();
			for (int i = 0; i < paramValueArr.length; i++) {
				String val = paramValueArr[i].trim();
				BsonDocument dbo = new BsonDocument();
				dbo.put(type, new BsonString(val));
				subObjectList.add(dbo);
			}
			if (subObjectList.isEmpty() == false) {
				BsonDocument query = new BsonDocument();
				query.put(field, new BsonDocument("$in", subObjectList));
				orQueries.add(query);
			}
		}
		if (orQueries.size() != 0) {
			BsonDocument queryObject = new BsonDocument();
			queryObject.put("$or", orQueries);
			return queryObject;
		} else {
			return null;
		}
	}
 
Example 5
Source File: ChronoGraph.java    From epcis with Apache License 2.0 5 votes vote down vote up
public ArrayList<CachedChronoVertex> getCachedChronoVertices(BsonArray filters, String sortKey, Boolean isDesc,
		Integer limit) {
	ArrayList<CachedChronoVertex> vList = new ArrayList<CachedChronoVertex>();
	// Merge All the queries with $and
	CachedChronoGraph g = new CachedChronoGraph();
	BsonDocument baseQuery = new BsonDocument();
	FindIterable<BsonDocument> cursor;
	if (filters.isEmpty() == false) {
		baseQuery.put("$and", filters);
		cursor = vertices.find(baseQuery);
	} else {
		cursor = vertices.find();
	}
	if (sortKey != null) {
		if (isDesc == null)
			cursor.sort(new BsonDocument(sortKey, new BsonInt32(-1)));
		else if (isDesc == true) {
			cursor.sort(new BsonDocument(sortKey, new BsonInt32(-1)));
		} else
			cursor.sort(new BsonDocument(sortKey, new BsonInt32(1)));
	}
	if (limit != null)
		cursor.limit(limit);

	MongoCursor<BsonDocument> iter = cursor.iterator();
	while (iter.hasNext()) {
		BsonDocument doc = iter.next();
		String vid = doc.remove("_id").asString().getValue();
		CachedChronoVertex v = g.getChronoVertex(vid);
		v.setProperties(doc);
		vList.add(v);
	}
	return vList;
}