(self)
If an Incident was included in the STIX package, its
        related_indicators attribute is used to relate objects to the event.
        Any objects without an explicit relationship to the event are
        related using type "Related_To".

        Objects are related to each other using the relationships listed in
        their related_indicators attribute.
If an Incident was included in the STIX package, its
        related_indicators attribute is used to relate objects to the event.
        Any objects without an explicit relationship to the event are
        related using type "Related_To".
If an Incident was included in the STIX package its related_indicators attribute is used to relate objects to the event . Any objects without an explicit relationship to the event are related using type Related_To .
def relate_objects(self):
        """
        If an Incident was included in the STIX package, its
        related_indicators attribute is used to relate objects to the event.
        Any objects without an explicit relationship to the event are
        related using type "Related_To".

        Objects are related to each other using the relationships listed in
        their related_indicators attribute.
        """

        if self.preview: # Previews don't include relationships
            return

        analyst = self.source_instance.analyst
        valid_rel_types = RelationshipTypes.values()

        # If package-level Events exists, relate TLOs to them
        if self.pkg_event:
            evt = self.pkg_event
            for pkg_id, imported in self.importedByPkg.iteritems():
                sub_pkg = self.updates[self.imported[pkg_id][1]]
                if pkg_id in self.pkg_rels: # Use provided relationship data if available
                    rel_type = self.pkg_rels[pkg_id][0]
                    if rel_type not in valid_rel_types:
                        rel_type = RelationshipTypes.RELATED_TO
                    confidence = self.pkg_rels[pkg_id][1]
                else:
                    rel_type = RelationshipTypes.RELATED_TO
                    confidence='Unknown'
                for tlo_meta in imported.itervalues():
                    evt.add_relationship(self.updates[tlo_meta[1]],
                                         rel_type=rel_type,
                                         rel_confidence=confidence,
                                         analyst=analyst)
                    sub_pkg.add_relationship(self.updates[tlo_meta[1]],
                                             rel_type=RelationshipTypes.RELATED_TO,
                                             rel_confidence='Unknown',
                                             analyst=analyst)
                sub_pkg.save(username=analyst)
            evt.save(username=analyst)

        # relate objects to each other
        for rel in self.relationships:
            for l_id in self.idMap.get(rel[0], [rel[0]]):
                for r_id in self.idMap.get(rel[2], [rel[2]]):
                    if (l_id in self.imported and r_id in self.imported and
                        l_id != r_id):
                        left = self.updates[self.imported[l_id][1]]
                        right = self.updates[self.imported[r_id][1]]
                        if left != right:
                            rel_type = rel[1]
                            if rel_type not in valid_rel_types:
                                rel_type = RelationshipTypes.RELATED_TO
                            left.add_relationship(right,
                                                  rel_type=rel_type,
                                                  rel_confidence=rel[3],
                                                  analyst=analyst)

        # save objects
        for id_ in self.imported:
            self.updates[self.imported[id_][1]].save(username=analyst)
def relate_objects ( self ) : if self . preview : # Previews don't include relationships return analyst = self . source_instance . analyst valid_rel_types = RelationshipTypes . values ( ) # If package-level Events exists, relate TLOs to them if self . pkg_event : evt = self . pkg_event for pkg_id , imported in self . importedByPkg . iteritems ( ) : sub_pkg = self . updates [ self . imported [ pkg_id ] [ 1 ] ] if pkg_id in self . pkg_rels : # Use provided relationship data if available rel_type = self . pkg_rels [ pkg_id ] [ 0 ] if rel_type not in valid_rel_types : rel_type = RelationshipTypes . RELATED_TO confidence = self . pkg_rels [ pkg_id ] [ 1 ] else : rel_type = RelationshipTypes . RELATED_TO confidence = 'Unknown' for tlo_meta in imported . itervalues ( ) : evt . add_relationship ( self . updates [ tlo_meta [ 1 ] ] , rel_type = rel_type , rel_confidence = confidence , analyst = analyst ) sub_pkg . add_relationship ( self . updates [ tlo_meta [ 1 ] ] , rel_type = RelationshipTypes . RELATED_TO , rel_confidence = 'Unknown' , analyst = analyst ) sub_pkg . save ( username = analyst ) evt . save ( username = analyst ) # relate objects to each other for rel in self . relationships : for l_id in self . idMap . get ( rel [ 0 ] , [ rel [ 0 ] ] ) : for r_id in self . idMap . get ( rel [ 2 ] , [ rel [ 2 ] ] ) : if ( l_id in self . imported and r_id in self . imported and l_id != r_id ) : left = self . updates [ self . imported [ l_id ] [ 1 ] ] right = self . updates [ self . imported [ r_id ] [ 1 ] ] if left != right : rel_type = rel [ 1 ] if rel_type not in valid_rel_types : rel_type = RelationshipTypes . RELATED_TO left . add_relationship ( right , rel_type = rel_type , rel_confidence = rel [ 3 ] , analyst = analyst ) # save objects for id_ in self . imported : self . updates [ self . imported [ id_ ] [ 1 ] ] . save ( username = analyst )