if (isLocalSource(key)) {
return localStore().get(key);
}
Connector connector = connectors.getConnectorForSourceKey(sourceKey(key));
if (connector != null) {
Document document = null;
if (connector instanceof Pageable && PageKey.isValidFormat(key)) {
// a page was requested
PageKey pageKey = new PageKey(key);
String parentId = pageKey.getParentId();
pageKey = pageKey.withParentId(documentIdFromNodeKey(parentId));
document = ((Pageable)connector).getChildren(pageKey);
} else {
// interpret the key as a regular node id
String docId = documentIdFromNodeKey(key);
document = connector.getDocumentById(docId);
}
if (document != null) {
// clone the document, so we don't alter the original
EditableDocument editableDocument = replaceConnectorIdsWithNodeKeys(document, connector.getSourceName());
editableDocument = updateCachingTtl(connector, editableDocument);
editableDocument = updateQueryable(connector, editableDocument);
// Extract any embedded documents ...
Object removedContainer = editableDocument.remove(DocumentTranslator.EMBEDDED_DOCUMENTS);
if (removedContainer instanceof EditableDocument) {
EditableDocument embeddedDocs = (EditableDocument)removedContainer;
for (Document.Field field : embeddedDocs.fields()) {
String id = field.getName();
Document doc = field.getValueAsDocument();
// Place the embedded document in the local value store ...
if (doc != null) localStore().put(id, doc);
}
}
return new FederatedSchematicEntry(editableDocument);