use of com.eightkdata.mongowp.bson.BsonType in project torodb by torodb.
the class ReplicaSetConfig method parseCustomWriteConcerns.
private static Map<String, ReplicaSetTagPattern> parseCustomWriteConcerns(BsonDocument bson) throws TypesMismatchException, NoSuchKeyException, BadValueException {
Map<String, ReplicaSetTagPattern> map = new HashMap<>(bson.size());
for (Entry<?> customWriteNameEntry : bson) {
BsonDocument constraintDoc = BsonReaderTool.getDocument(bson, customWriteNameEntry.getKey());
Map<String, Integer> constraintMap = new HashMap<>(constraintDoc.size());
for (Entry<?> tagEntry : constraintDoc) {
int intValue;
try {
intValue = tagEntry.getValue().asNumber().intValue();
} catch (UnsupportedOperationException ex) {
String fieldName = SETTINGS_FIELD.getFieldName() + '.' + GET_LAST_ERROR_MODES_FIELD.getFieldName() + '.' + customWriteNameEntry + '.' + constraintDoc;
BsonType tagType = tagEntry.getValue().getType();
throw new TypesMismatchException(fieldName, "number", tagType, "Expected " + fieldName + " to be a number, not " + tagType.toString().toLowerCase(Locale.ROOT));
}
if (intValue <= 0) {
String fieldName = SETTINGS_FIELD.getFieldName() + '.' + GET_LAST_ERROR_MODES_FIELD.getFieldName() + '.' + customWriteNameEntry + '.' + constraintDoc;
throw new BadValueException("Value of " + fieldName + " must be positive, but found " + intValue);
}
constraintMap.put(tagEntry.getKey(), intValue);
}
map.put(customWriteNameEntry.getKey(), new ReplicaSetTagPattern(constraintMap));
}
return map;
}
Aggregations