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

The following examples show how to use org.bson.BsonArray#iterator() . 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: MongoReaderUtil.java    From epcis with Apache License 2.0 5 votes vote down vote up
static EPCISEventExtensionType putEPCISEventExtensionType(BsonDocument dbObject, int zone) {
	EPCISEventExtensionType eeet = new EPCISEventExtensionType();
	if (dbObject.get("eventID") != null) {
		eeet.setEventID(dbObject.getString("eventID").getValue());
	} else {
		if (dbObject.containsKey("_id")) {
			eeet.setEventID(dbObject.getObjectId("_id").getValue().toHexString());
		}
	}
	if (dbObject.get("errorDeclaration") != null) {
		ErrorDeclarationType edt = new ErrorDeclarationType();
		BsonDocument error = dbObject.getDocument("errorDeclaration");
		if (error.containsKey("declarationTime")) {
			edt.setDeclarationTime(getXMLGregorianCalendar(error.getDateTime("declarationTime")));
		}
		if (error.containsKey("reason")) {
			edt.setReason(error.getString("reason").getValue());
		}
		if (error.containsKey("correctiveEventIDs")) {
			BsonArray correctiveEventIDs = error.getArray("correctiveEventIDs");
			List<String> correctiveIDs = new ArrayList<String>();
			Iterator<BsonValue> cIDIterator = correctiveEventIDs.iterator();
			while (cIDIterator.hasNext()) {
				String cID = cIDIterator.next().asString().getValue();
				correctiveIDs.add(cID);
			}
			if (correctiveIDs.size() != 0) {
				CorrectiveEventIDsType ceit = new CorrectiveEventIDsType();
				ceit.setCorrectiveEventID(correctiveIDs);
				edt.setCorrectiveEventIDs(ceit);
			}
		}
		if (error.containsKey("any")) {
			edt.setAny(putAny(error.getDocument("any"), null));
		}
		eeet.setErrorDeclaration(edt);
	}
	return eeet;
}
 
Example 2
Source File: TriggerEngine.java    From epcis with Apache License 2.0 5 votes vote down vote up
private static Set<String> addEPCtoSet(Set<String> epcSet, BsonArray epcList) {
	Iterator<BsonValue> epcIterator = epcList.iterator();
	while (epcIterator.hasNext()) {
		BsonDocument epcDocument = epcIterator.next().asDocument();
		epcSet.add(epcDocument.getString("epc").getValue());
	}
	return epcSet;
}
 
Example 3
Source File: TriggerEngine.java    From epcis with Apache License 2.0 5 votes vote down vote up
private static Set<String> addEPCClasstoSet(Set<String> epcSet, BsonArray epcList) {
	Iterator<BsonValue> epcIterator = epcList.iterator();
	while (epcIterator.hasNext()) {
		BsonDocument epcDocument = epcIterator.next().asDocument();
		epcSet.add(epcDocument.getString("epcClass").getValue());
	}
	return epcSet;
}
 
Example 4
Source File: MongoQueryUtil.java    From epcis with Apache License 2.0 5 votes vote down vote up
static BsonDocument getQueryObject(String[] fieldArr, BsonArray paramArray) {

		BsonArray orQueries = new BsonArray();
		for (String field : fieldArr) {
			Iterator<BsonValue> paramIterator = paramArray.iterator();
			BsonArray pureStringParamArray = new BsonArray();
			while (paramIterator.hasNext()) {
				BsonValue param = paramIterator.next();
				if (param instanceof BsonRegularExpression) {
					BsonDocument regexQuery = new BsonDocument(field, new BsonDocument("$regex", param));
					orQueries.add(regexQuery);
				} else {
					pureStringParamArray.add(param);
				}
			}
			if (pureStringParamArray.size() != 0) {
				BsonDocument stringInQueries = new BsonDocument(field, new BsonDocument("$in", pureStringParamArray));
				orQueries.add(stringInQueries);
			}
		}
		if (orQueries.size() != 0) {
			BsonDocument queryObject = new BsonDocument();
			queryObject.put("$or", orQueries);
			return queryObject;
		} else {
			return null;
		}
	}
 
Example 5
Source File: MongoReaderUtil.java    From epcis with Apache License 2.0 5 votes vote down vote up
static EPCISEventExtensionType putEPCISEventExtensionType(BsonDocument dbObject, int zone) {
	EPCISEventExtensionType eeet = new EPCISEventExtensionType();
	if (dbObject.get("eventID") != null) {
		eeet.setEventID(dbObject.getString("eventID").getValue());
	} else {
		if (dbObject.containsKey("_id")) {
			eeet.setEventID(dbObject.getString("_id").getValue());
		}
	}
	if (dbObject.get("errorDeclaration") != null) {
		ErrorDeclarationType edt = new ErrorDeclarationType();
		BsonDocument error = dbObject.getDocument("errorDeclaration");
		if (error.containsKey("declarationTime")) {
			edt.setDeclarationTime(getXMLGregorianCalendar(error.getDateTime("declarationTime")));
		}
		if (error.containsKey("reason")) {
			edt.setReason(error.getString("reason").getValue());
		}
		if (error.containsKey("correctiveEventIDs")) {
			BsonArray correctiveEventIDs = error.getArray("correctiveEventIDs");
			List<String> correctiveIDs = new ArrayList<String>();
			Iterator<BsonValue> cIDIterator = correctiveEventIDs.iterator();
			while (cIDIterator.hasNext()) {
				String cID = cIDIterator.next().asString().getValue();
				correctiveIDs.add(cID);
			}
			if (correctiveIDs.size() != 0) {
				CorrectiveEventIDsType ceit = new CorrectiveEventIDsType();
				ceit.setCorrectiveEventID(correctiveIDs);
				edt.setCorrectiveEventIDs(ceit);
			}
		}
		if (error.containsKey("any")) {
			edt.setAny(putAny(error.getDocument("any"), null));
		}
		eeet.setErrorDeclaration(edt);
	}
	return eeet;
}
 
Example 6
Source File: TriggerEngine.java    From epcis with Apache License 2.0 5 votes vote down vote up
private static Set<String> addEPCtoSet(Set<String> epcSet, BsonArray epcList) {
	Iterator<BsonValue> epcIterator = epcList.iterator();
	while (epcIterator.hasNext()) {
		BsonDocument epcDocument = epcIterator.next().asDocument();
		epcSet.add(epcDocument.getString("epc").getValue());
	}
	return epcSet;
}
 
Example 7
Source File: TriggerEngine.java    From epcis with Apache License 2.0 5 votes vote down vote up
private static Set<String> addEPCClasstoSet(Set<String> epcSet, BsonArray epcList) {
	Iterator<BsonValue> epcIterator = epcList.iterator();
	while (epcIterator.hasNext()) {
		BsonDocument epcDocument = epcIterator.next().asDocument();
		epcSet.add(epcDocument.getString("epcClass").getValue());
	}
	return epcSet;
}
 
Example 8
Source File: MongoQueryUtil.java    From epcis with Apache License 2.0 5 votes vote down vote up
static BsonDocument getQueryObject(String[] fieldArr, BsonArray paramArray) {

		BsonArray orQueries = new BsonArray();
		for (String field : fieldArr) {
			Iterator<BsonValue> paramIterator = paramArray.iterator();
			BsonArray pureStringParamArray = new BsonArray();
			while (paramIterator.hasNext()) {
				BsonValue param = paramIterator.next();
				if (param instanceof BsonRegularExpression) {
					BsonDocument regexQuery = new BsonDocument(field, new BsonDocument("$regex", param));
					orQueries.add(regexQuery);
				} else {
					pureStringParamArray.add(param);
				}
			}
			if (pureStringParamArray.size() != 0) {
				BsonDocument stringInQueries = new BsonDocument(field, new BsonDocument("$in", pureStringParamArray));
				orQueries.add(stringInQueries);
			}
		}
		if (orQueries.size() != 0) {
			BsonDocument queryObject = new BsonDocument();
			queryObject.put("$or", orQueries);
			return queryObject;
		} else {
			return null;
		}
	}