// Level 2: the "dna:workspaces" node
// Level 3: a node for each workspace in the federated repository
// Level 4: the "dna:projections" nodes
// Level 5: a node below "dna:projections" for each projection, with properties for the source name,
// workspace name, cache expiration time, and projection rules
Subgraph repositories = repositoryContext.getConfiguration(5);
// Get the name of the default workspace ...
String defaultWorkspaceName = null;
Property defaultWorkspaceNameProperty = repositories.getRoot().getProperty(DnaLexicon.DEFAULT_WORKSPACE_NAME);
if (defaultWorkspaceNameProperty != null) {
// Set the name using the property if there is one ...
defaultWorkspaceName = strings.create(defaultWorkspaceNameProperty.getFirstValue());
}
// Get the default expiration time for the repository ...
CachePolicy defaultCachePolicy = null;
Property timeToExpire = repositories.getRoot().getProperty(DnaLexicon.TIME_TO_EXPIRE);
if (timeToExpire != null && !timeToExpire.isEmpty()) {
long timeToCacheInMillis = longs.create(timeToExpire.getFirstValue());
defaultCachePolicy = new BasicCachePolicy(timeToCacheInMillis, TimeUnit.MILLISECONDS).getUnmodifiable();
}
// Level 2: The "dna:workspaces" node ...
Node workspacesNode = repositories.getNode(DnaLexicon.WORKSPACES);
if (workspacesNode == null) {
I18n msg = GraphI18n.requiredNodeDoesNotExistRelativeToNode;
throw new RepositorySourceException(msg.text(DnaLexicon.WORKSPACES.getString(registry),
repositories.getLocation().getPath().getString(registry),
repositories.getGraph().getCurrentWorkspaceName(),
repositories.getGraph().getSourceName()));
}
// Level 3: The workspace nodes ...
LinkedList<FederatedWorkspace> workspaces = new LinkedList<FederatedWorkspace>();
for (Location workspace : workspacesNode) {
// Get the name of the workspace ...
String workspaceName = null;
SubgraphNode workspaceNode = repositories.getNode(workspace);
Property workspaceNameProperty = workspaceNode.getProperty(DnaLexicon.WORKSPACE_NAME);
if (workspaceNameProperty != null) {
// Set the name using the property if there is one ...
workspaceName = strings.create(workspaceNameProperty.getFirstValue());
}
if (workspaceName == null) {
// Otherwise, set the name using the local name of the workspace node ...
workspaceName = workspace.getPath().getLastSegment().getName().getLocalName();
}
// Level 4: the "dna:projections" node ...
Node projectionsNode = workspaceNode.getNode(DnaLexicon.PROJECTIONS);
if (projectionsNode == null) {
I18n msg = GraphI18n.requiredNodeDoesNotExistRelativeToNode;
throw new RepositorySourceException(getName(), msg.text(DnaLexicon.PROJECTIONS.getString(registry),
workspaceNode.getLocation()
.getPath()
.getString(registry),
repositories.getGraph().getCurrentWorkspaceName(),
repositories.getGraph().getSourceName()));
}
// Level 5: the projection nodes ...
List<Projection> sourceProjections = new LinkedList<Projection>();
for (Location projection : projectionsNode) {
Node projectionNode = repositories.getNode(projection);
sourceProjections.add(createProjection(executionContext, projectionParser, projectionNode));
}
// Create the federated workspace configuration ...
FederatedWorkspace space = new FederatedWorkspace(repositoryContext, name, workspaceName, sourceProjections,