Ejemplo n.º 1
0
def _createImmediateRelsWhereChild(currentNode):
    """
    Create transitive relationships for immeditate relationships where the
    given node is the child.
    """
    currentOid = currentNode.getOid()

    # Add relationships from this node to its immediate parents
    relsWithParents = Relationships.getByChildOidRelType(
        currentOid, Relationships.PART_OF)
    for parentRel in relsWithParents:
        parentOid = parentRel.getParentOid()
        if not exists(Relationships.PART_OF, descendentOid = currentOid,
                      ancestorOid = parentOid):
            start, stop = Nodes.getStageWindowForNodeOid(currentOid)

            DbAccess.writeSql("/* direct */")
            createRelationshipTransitive(
                Relationships.PART_OF, descendentOid = currentOid,
                ancestorOid = parentOid)

            # Add relationships based on its parents' already defined
            # transitive relationships.  Transitive relationships
            # do not cross relationship types.
            ancestorRels = _byDescendentOidRelType.get((parentOid,
                                                        Relationships.PART_OF))
            if ancestorRels != None:
                for ancestorRel in ancestorRels.itervalues():
                    ancestorOid = ancestorRel.getAncestorOid()
                    ancestor = Nodes.getByOid(ancestorOid)
                    if not exists(relType = Relationships.PART_OF,
                                  descendentOid = currentOid,
                                  ancestorOid = ancestorOid):
                        # if reltype is part-of then only generate a transitive
                        # relationship if the ancestor and this node overlap in time.
                        # Group ancestors sometimes do not overlap with their
                        # descendents.
                        ancestorStart, ancestorStop = (
                            Nodes.getStageWindowForNodeOid(ancestorOid))
                        if (start.getSequence() > ancestorStop.getSequence() or
                            stop.getSequence()  < ancestorStart.getSequence()):
                            if not ancestor.isGroup():
                                # oops, supposed to be a group
                                Util.fatalError([
                                    "Ancestor stage window does not overlap " +
                                    "with descendent stage window and",
                                    "ancestor is not a group.",
                                    "Ancestor ID:   " + ancestor.getPublicId() +
                                    " Name: " + ancestor.getName(),
                                    "  Start-Stop: " + ancestorStart.getName() +
                                    "-" + ancestorStop.getName(),
                                    "Descendent ID: " + currentNode.getPublicId() +
                                    " Name: " + currentNode.getName(),
                                    "  Start-Stop: " + start.getName() +
                                    "-" + stop.getName()])
                        else:
                            DbAccess.writeSql("/* from ancestor */")
                            createRelationshipTransitive(Relationships.PART_OF,
                                                         descendentOid = currentOid,
                                                         ancestorOid = ancestorOid)
    return