@Override
public RecordScan fromJson(JsonNode nodeNode, Namespaces namespaces, LRepository repository)
throws JsonFormatException, RepositoryException, InterruptedException {
if (nodeNode == null || nodeNode.isNull()) {
return new RecordScan();
}
if (!nodeNode.isObject()) {
throw new JsonFormatException("Expected a json object for record scan, got: " +
nodeNode.getClass().getName());
}
ObjectNode node = (ObjectNode) nodeNode;
RecordScan scan = new RecordScan();
namespaces = NamespacesConverter.fromContextJson(node, namespaces);
String startRecordId = JsonUtil.getString(node, "startRecordId", null);
if (startRecordId != null) {
scan.setStartRecordId(repository.getIdGenerator().fromString(startRecordId));
}
String stopRecordId = JsonUtil.getString(node, "stopRecordId", null);
if (stopRecordId != null) {
scan.setStopRecordId(repository.getIdGenerator().fromString(stopRecordId));
}
byte[] rawStartRecordId = JsonUtil.getBinary(node, "rawStartRecordId", null);
if (rawStartRecordId != null) {
scan.setRawStartRecordId(rawStartRecordId);
}
byte[] rawStopRecordId = JsonUtil.getBinary(node, "rawStopRecordId", null);
if (rawStopRecordId != null) {
scan.setRawStopRecordId(rawStopRecordId);
}
ObjectNode filter = JsonUtil.getObject(node, "recordFilter", null);
if (filter != null) {
scan.setRecordFilter(RecordFilterJsonConverters.INSTANCE.fromJson(filter, namespaces, repository,
RecordFilterJsonConverters.INSTANCE));
}
ObjectNode returnFieldsNode = JsonUtil.getObject(node, "returnFields", null);
if (returnFieldsNode != null) {
ReturnFields returnFields = new ReturnFields();
returnFields.setType(ReturnFields.Type.valueOf(JsonUtil.getString(returnFieldsNode, "type")));
ArrayNode fieldsArray = JsonUtil.getArray(returnFieldsNode, "fields", null);
if (fieldsArray != null) {
List<QName> fields = new ArrayList<QName>();
for (JsonNode subFilterNode : fieldsArray) {
if (!subFilterNode.isTextual()) {
throw new JsonFormatException("ReturnFields.fields should be a string array, found: "
+ subFilterNode.getClass().getName());
}
fields.add(QNameConverter.fromJson(subFilterNode.getTextValue(), namespaces));
}
returnFields.setFields(fields);
}
scan.setReturnFields(returnFields);
}
scan.setCaching(JsonUtil.getInt(node, "caching", scan.getCaching()));
scan.setCacheBlocks(JsonUtil.getBoolean(node, "cacheBlocks", scan.getCacheBlocks()));
return scan;
}