Map<String, String> workspaceNameByKey = workspaceNamesByKey();
Iterator<ChildReference> iter = federationChildRefs.iterator(ModeShapeLexicon.PROJECTION);
while (iter.hasNext()) {
ChildReference projectionRef = iter.next();
NodeKey projectionRefKey = projectionRef.getKey();
CachedNode projectionNode = systemSession.getNode(projectionRefKey);
String externalNodeKeyString = projectionNode.getProperty(ModeShapeLexicon.EXTERNAL_NODE_KEY, systemSession)
.getFirstValue().toString();
assert externalNodeKeyString != null;
String projectedNodeKeyString = projectionNode.getProperty(ModeShapeLexicon.PROJECTED_NODE_KEY, systemSession)
.getFirstValue().toString();
assert projectedNodeKeyString != null;
String alias = projectionNode.getProperty(ModeShapeLexicon.PROJECTION_ALIAS, systemSession).getFirstValue()
.toString();
assert alias != null;
Projection projection = new Projection(externalNodeKeyString, projectedNodeKeyString, alias);
if (!validate || repository.documentStore().containsKey(externalNodeKeyString)) {
result.add(projection);
} else {
// we have a projection that is not valid anymore
invalidProjections.add(projection);
// remove the projection from the system area first
federationNode.removeChild(systemSession, projectionRefKey);
systemSession.destroy(projectionRefKey);
// then update the internal (parent) node and remove its external child
NodeKey projectedNodeKey = new NodeKey(projectedNodeKeyString);
String wsName = workspaceNameByKey.get(projectedNodeKey.getWorkspaceKey());
if (!StringUtil.isBlank(wsName)) {
SessionCache sessionCache = repository.repositoryCache().createSession(repository.context(), wsName, false);
MutableCachedNode parentNode = sessionCache.mutable(projectedNodeKey);
parentNode.removeFederatedSegment(externalNodeKeyString);
sessionCache.save();