throws InterruptedException, RepositoryException, JsonFormatException {
LRepository repository = context.repository;
Namespaces namespaces = context.namespaces;
JsonNode node = handle.node;
Record record = readCommonRecordAspects(handle, context, true);
String id = getString(node, "id", null);
if (id != null) {
record.setId(repository.getIdGenerator().fromString(id));
}
ArrayNode fieldsToDelete = getArray(node, "fieldsToDelete", null);
if (fieldsToDelete != null) {
for (int i = 0; i < fieldsToDelete.size(); i++) {
JsonNode fieldToDelete = fieldsToDelete.get(i);
if (!fieldToDelete.isTextual()) {
throw new JsonFormatException("fieldsToDelete should be an array of strings, encountered: " + fieldToDelete);
} else {
QName qname = QNameConverter.fromJson(fieldToDelete.getTextValue(), namespaces);
record.getFieldsToDelete().add(qname);
}
}
}
ObjectNode attributes = getObject(node, "attributes", null);
if (attributes != null) {
Iterator<Map.Entry<String, JsonNode>> it = attributes.getFields();
while(it.hasNext()) {
Map.Entry<String, JsonNode> entry = it.next();
record.getAttributes().put(entry.getKey(), entry.getValue().getTextValue());
}
}
Map<QName, MetadataBuilder> metadataBuilders = null;
ObjectNode metadata = getObject(node, "metadata", null);
if (metadata != null) {
metadataBuilders = new HashMap<QName, MetadataBuilder>();
Iterator<Map.Entry<String, JsonNode>> it = metadata.getFields();
while (it.hasNext()) {
Map.Entry<String, JsonNode> entry = it.next();
QName qname = QNameConverter.fromJson(entry.getKey(), namespaces);
MetadataBuilder builder = readMetadata(entry.getValue(), qname);
metadataBuilders.put(qname, builder);
}
}
ObjectNode metadataToDelete = getObject(node, "metadataToDelete", null);
if (metadataToDelete != null) {
if (metadataBuilders == null) {
metadataBuilders = new HashMap<QName, MetadataBuilder>();
}
Iterator<Map.Entry<String, JsonNode>> it = metadataToDelete.getFields();
while (it.hasNext()) {
Map.Entry<String, JsonNode> entry = it.next();
QName qname = QNameConverter.fromJson(entry.getKey(), namespaces);
MetadataBuilder builder = readMetadataToDelete(entry.getValue(), metadataBuilders.get(qname), qname);
metadataBuilders.put(qname, builder);
}
}
if (metadataBuilders != null) {
for (Map.Entry<QName, MetadataBuilder> entry : metadataBuilders.entrySet()) {
record.setMetadata(entry.getKey(), entry.getValue().build());
}
}
return record;
}