if (mappingsByConnectorSourceName == null) {
// We construct these immutable and idempotent mappings (for all connectors) lazily,
// but we still need to synchronize upon the creation of them ...
synchronized (this) {
if (mappingsByConnectorSourceName == null) {
final RunningState repository = repository();
final PathFactory pathFactory = repository().context().getValueFactories().getPathFactory();
Map<String, BasicPathMappings> mappingsByConnectorSourceName = new HashMap<>();
Map<String, String> workspaceNamesByKey = workspaceNamesByKey();
// Iterate through the projections ...
for (Projection projection : this.projections.values()) {
final String alias = projection.getAlias();
String externalKeyStr = projection.getExternalNodeKey(); // contains the source & workspace keys ...
final NodeKey externalKey = new NodeKey(externalKeyStr);
final String externalDocId = externalKey.getIdentifier();
// Find the connector that serves up this external key ...
Connector conn = getConnectorForSourceKey(externalKey.getSourceKey());
if (conn == null) {
// should never happen
throw new IllegalStateException("External source key: " + externalKey.getSourceKey()
+ " has no matching connector");
}
if (conn != connector) {
// since projections are stored in bulk (not on a per-connector basis), we only care about the
// projection
// if it belongs to this connector
continue;
}
// Find the path mappings ...
BasicPathMappings mappings = mappingsByConnectorSourceName.get(connectorSourceName);
if (mappings == null) {
mappings = new BasicPathMappings(connectorSourceName, pathFactory);
mappingsByConnectorSourceName.put(connectorSourceName, mappings);
}
// Now add the path mapping for this projection. First, find the path of the one projected node ...
String projectedKeyStr = projection.getProjectedNodeKey();
NodeKey projectedKey = new NodeKey(projectedKeyStr);
String workspaceName = workspaceNamesByKey.get(projectedKey.getWorkspaceKey());
if (workspaceName == null) continue;
try {
WorkspaceCache cache = repository.repositoryCache().getWorkspaceCache(workspaceName);
AllPathsCache allPathsCache = new AllPathsCache(cache, null, pathFactory);
CachedNode node = cache.getNode(projectedKey);
for (Path nodePath : allPathsCache.getPaths(node)) {
Path internalPath = pathFactory.create(nodePath, alias);
// Then find the path(s) for the external node with the aforementioned key ...