def _extract_resolved_attributes(self, proj_ctx: 'ProjectionContext') -> 'ResolvedAttributeSet': """Create resolved attribute set based on the CurrentResolvedAttribute array""" resolved_attribute_set = ResolvedAttributeSet() resolved_attribute_set.attribute_context = proj_ctx._current_attribute_context for pas in proj_ctx._current_attribute_state_set._states: resolved_attribute_set.merge(pas._current_resolved_attribute, pas._current_resolved_attribute.att_ctx) return resolved_attribute_set
def associate_tree_copy_with_attributes(self, res_opt: ResolveOptions, ras: ResolvedAttributeSet) -> bool: # deep copy the tree. while doing this also collect a map from old attCtx to new equivalent # this is where the returned tree fits in cached_ctx = ras.attribute_context if cached_ctx._copy_attribute_context_tree(res_opt, self) is None: return False ras.attribute_context = self # run over the resolved attributes in the copy and use the map to swap the old ctx for the new version def _fix_resolve_attribute_ctx(ras_sub: ResolvedAttributeSet) -> None: for ra in ras_sub._set: ra.att_ctx = res_opt._map_old_ctx_to_new_ctx[ra.att_ctx] # the target for a resolved att can be a typeAttribute OR it can be another resolvedAttributeSet (meaning a group) if isinstance(ra.target, ResolvedAttributeSet): cast(ResolvedAttributeSet, ra.target).attribute_context = ra.att_ctx _fix_resolve_attribute_ctx( cast(ResolvedAttributeSet, ra.target)) _fix_resolve_attribute_ctx(ras) # now fix any lineage references def _fix_att_ctx_node_lineage( ac: CdmAttributeContext, ac_parent: Optional[CdmAttributeContext] = None) -> None: if ac is None: return if ac_parent and ac.parent and ac.parent.explicit_reference: ac.parent.explicit_reference = ac_parent if ac.lineage and len(ac.lineage) > 0: # fix lineage for lin in ac.lineage: if lin.explicit_reference: # swap the actual object for the one in the new tree lin.explicit_reference = res_opt._map_old_ctx_to_new_ctx[ cast(CdmAttributeContext, lin.explicit_reference)] if not ac.contents: return # look at all children for sub_sub in ac.contents: _fix_att_ctx_node_lineage(sub_sub, ac) _fix_att_ctx_node_lineage(self, None) return True
def _extract_resolved_attributes( self, proj_ctx: 'ProjectionContext', att_ctx_under: CdmAttributeContext) -> 'ResolvedAttributeSet': """Create resolved attribute set based on the CurrentResolvedAttribute array""" resolved_attribute_set = ResolvedAttributeSet() resolved_attribute_set.attribute_context = att_ctx_under if not proj_ctx: logger.error(self.ctx, self._TAG, '_extract_resolved_attributes', self.at_corpus_path, CdmLogCode.ERR_PROJ_FAILED_TO_RESOLVE) return resolved_attribute_set for pas in proj_ctx._current_attribute_state_set._states: resolved_attribute_set.merge(pas._current_resolved_attribute) return resolved_attribute_set