Example #1
0
    def process_indicators(self, doc_dict, domain, namespaces):
        case_type = doc_dict.get('type')
        if not case_type:
            pillow_eval_logging.info(
                "CaseIndicatorPillow did not find a case type for %(domain)s, "
                "doc id: %(doc_id)s" % {
                    'domain': domain,
                    'doc_id': doc_dict['_id'],
                })
            return

        case_indicators = []
        for namespace in namespaces:
            case_indicators.extend(
                CaseIndicatorDefinition.get_all(namespace,
                                                domain,
                                                case_type=case_type))

        if case_indicators:
            case_doc = CommCareCase.get(doc_dict['_id'])
            case_doc.update_indicators_in_bulk(case_indicators,
                                               logger=pillow_logging)
        else:
            pillow_eval_logging.info("CaseIndicatorPillow could not find "
                                     "case indicators for %(domain)s, "
                                     "doc id: %(doc_id)s" % {
                                         'domain': domain,
                                         'doc_id': doc_dict['_id'],
                                     })

        xform_ids = doc_dict.get('xform_ids', [])
        if not xform_ids:
            pillow_eval_logging.info("CaseIndicatorPillow could not find "
                                     "related xforms for case in %(domain)s, "
                                     "doc id: %(doc_id)s" % {
                                         'domain': domain,
                                         'doc_id': doc_dict['_id'],
                                     })

        for xform_id in xform_ids:
            try:
                with XFormInstance.get_locked_obj(_id=xform_id) as xform_doc:
                    if not xform_doc.xmlns:
                        continue
                    related_xform_indicators = []
                    for namespace in namespaces:
                        related_xform_indicators.extend(
                            CaseDataInFormIndicatorDefinition.get_all(
                                namespace, domain, xmlns=xform_doc.xmlns))
                    xform_doc.update_indicators_in_bulk(
                        related_xform_indicators,
                        logger=pillow_eval_logging,
                    )
            except ResourceNotFound:
                pillow_logging.error(
                    "[INDICATOR %(domain)s] Tried to form grab indicators "
                    "for %(xform_id)s "
                    "from case %(case_id)s and failed." % {
                        'domain': domain,
                        'xform_id': xform_id,
                        'case_id': doc_dict['_id'],
                    })
Example #2
0
    def process_indicators(self, doc_dict, domain, namespaces):
        case_type = doc_dict.get('type')
        if not case_type:
            pillow_eval_logging.info(
                "CaseIndicatorPillow did not find a case type for %(domain)s, "
                "doc id: %(doc_id)s" % {
                    'domain': domain,
                    'doc_id': doc_dict['_id'],
                }
            )
            return

        case_indicators = []
        for namespace in namespaces:
            case_indicators.extend(CaseIndicatorDefinition.get_all(
                namespace,
                domain,
                case_type=case_type
            ))

        if case_indicators:
            case_doc = CommCareCase.get(doc_dict['_id'])
            case_doc.update_indicators_in_bulk(case_indicators,
                                               logger=pillow_logging)
        else:
            pillow_eval_logging.info(
                "CaseIndicatorPillow could not find "
                "case indicators for %(domain)s, "
                "doc id: %(doc_id)s" % {
                    'domain': domain,
                    'doc_id': doc_dict['_id'],
                }
            )

        xform_ids = doc_dict.get('xform_ids', [])
        if not xform_ids:
            pillow_eval_logging.info(
                "CaseIndicatorPillow could not find "
                "related xforms for case in %(domain)s, "
                "doc id: %(doc_id)s" % {
                    'domain': domain,
                    'doc_id': doc_dict['_id'],
                }
            )

        for xform_id in xform_ids:
            try:
                with XFormInstance.get_locked_obj(_id=xform_id) as xform_doc:
                    if not xform_doc.xmlns:
                        continue
                    related_xform_indicators = []
                    for namespace in namespaces:
                        related_xform_indicators.extend(
                            CaseDataInFormIndicatorDefinition.get_all(
                                namespace,
                                domain,
                                xmlns=xform_doc.xmlns
                            )
                        )
                    xform_doc.update_indicators_in_bulk(
                        related_xform_indicators,
                        logger=pillow_eval_logging,
                    )
            except ResourceNotFound:
                pillow_logging.error(
                    "[INDICATOR %(domain)s] Tried to form grab indicators "
                    "for %(xform_id)s "
                    "from case %(case_id)s and failed." % {
                        'domain': domain,
                        'xform_id': xform_id,
                        'case_id': doc_dict['_id'],
                    }
                )