コード例 #1
0
ファイル: transaction.py プロジェクト: timhowes/sheepdog
    def get_nodes(self, ids):
        """Populates self.entities with nodes from :param:`ids`"""

        nodes = (self.db_driver.nodes().props(
            project_id=self.project_id).ids(ids).all())

        self.entities = [DeletionEntity(self, node) for node in nodes]

        # Look for missing entitites
        entity_ids = {e.node.node_id for e in self.entities}
        missing_ids = [ID for ID in ids if ID not in entity_ids]

        for ID in missing_ids:
            missing = DeletionEntity(self, MissingNode())
            missing.record_error('Entity not found.',
                                 keys=['id'],
                                 id=ID,
                                 type=EntityErrors.NOT_FOUND)
            self.entities.append(missing)

        # see DeletionEntity.related_cases() docstring for details
        if case_cache_enabled():
            self.related_cases = {
                node.node_id: [{
                    'id': c.node_id,
                    'submitter_id': c.submitter_id
                } for c in node._related_cases_from_cache]
                for node in nodes
            }
コード例 #2
0
 def json(self):
     """
     Return a JSON representation of transaction status, errors, entities,
     etc.
     """
     doc = dict(
         self.base_json,
         **{
             "created_entity_count": self.created_entity_count,
             "updated_entity_count": self.updated_entity_count,
         }
     )
     if case_cache_enabled():
         doc["cases_related_to_updated_entities_count"] = len(
             {
                 case["id"]
                 for entity in doc["entities"]
                 for case in entity["related_cases"]
                 if entity["action"] == "update"
             }
         )
         doc["cases_related_to_created_entities_count"] = len(
             {
                 case["id"]
                 for entity in doc["entities"]
                 for case in entity["related_cases"]
                 if entity["action"] == "create"
             }
         )
     return doc
コード例 #3
0
    def related_cases(self):
        """Gets related cases from shortcut edge

        """
        if not case_cache_enabled() or not self.node or not self.entity_type or not self.node.label:
            return []
        self.transaction.session.flush()

        def make_id(case):
            return {'id': case.node_id, 'submitter_id': case.submitter_id}

        return map(make_id, self.node._related_cases_from_cache)
コード例 #4
0
 def json(self):
     """
     Return a JSON representation of transaction status, errors, entities,
     etc.
     """
     doc = dict(
         self.base_json, **{
             'created_entity_count': self.created_entity_count,
             'updated_entity_count': self.updated_entity_count,
         })
     if case_cache_enabled():
         doc['cases_related_to_updated_entities_count'] = len({
             case['id']
             for entity in doc['entities']
             for case in entity['related_cases']
             if entity['action'] == "update"
         })
         doc['cases_related_to_created_entities_count'] = len({
             case['id']
             for entity in doc['entities']
             for case in entity['related_cases']
             if entity['action'] == "create"
         })
     return doc