Beispiel #1
0
    def index_imei_device(self, conn):
        """Method to index the Registration Device table."""

        try:
            ImeiDevice.create_index(conn)
            return "Registration Imeidevice indexed successfully"
        except SQLAlchemyError as e:
            raise e
    def sync_bulk_create(cls, reg_details, reg_device_id, app, ussd=None):
        """Create devices in bulk."""
        try:
            flatten_imeis = []

            if ussd is None:
                imeis_lists = ast.literal_eval(reg_details.imeis)
            else:
                imeis_lists = []
                ims = reg_details.imeis
                imeis_lists.append(list(ims.strip('}{').split(",")))

            for device_imeis in imeis_lists:

                device = cls(device_imeis[0][:8], reg_details.id,
                             reg_device_id)
                device.save()

                for imei in device_imeis:
                    flatten_imeis.append(imei)
                    imei_device = ImeiDevice(imei, device.id)
                    db.session.add(imei_device)
                    imei_object = ApprovedImeis.query.filter_by(
                        imei=imei[:14]).first()
                    if not imei_object:
                        approved_imei = ApprovedImeis(imei[:14],
                                                      reg_details.id,
                                                      'pending', 'add')
                        db.session.add(approved_imei)
                    elif imei_object and imei_object.status == 'removed':
                        imei_object.status = 'pending'
                        imei_object.removed = False
                        imei_object.request_id = reg_details.id
                        db.session.add(imei_object)
            reg_details.update_processing_status('Processed')
            reg_details.update_report_status('Processing')
            db.session.commit()

            task_id = Utilities.generate_summary(flatten_imeis,
                                                 reg_details.tracking_id)

            if task_id:
                Utilities.pool_summary_request(task_id, reg_details, app)
            else:
                reg_details.update_report_status('Failed')
                db.session.commit()
                exit()

            if app.config['AUTOMATE_IMEI_CHECK'] or ussd:
                if Device.auto_approve(task_id, reg_details, flatten_imeis,
                                       app):
                    app.logger.info(
                        "Auto Approved/Rejected Registration Application Id:" +
                        str(reg_details.id))

        except Exception as e:  # pragma: no cover
            reg_details.update_processing_status('Failed')
            reg_details.update_report_status('Failed')
            app.logger.exception(e)
            db.session.commit()
Beispiel #3
0
    def sync_bulk_create(cls, reg_details, reg_device_id, app):
        """Create devices in bulk."""
        try:
            flatten_imeis = []
            imeis_lists = ast.literal_eval(reg_details.imeis)
            for device_imeis in imeis_lists:
                device = cls(device_imeis[0][:8], reg_details.id, reg_device_id)
                device.save()
                for imei in device_imeis:
                    flatten_imeis.append(imei)
                    imei_device = ImeiDevice(imei, device.id)
                    db.session.add(imei_device)
                    imei_object = ApprovedImeis.query.filter_by(imei=imei[:14]).first()
                    if not imei_object:
                        approved_imei = ApprovedImeis(imei[:14], reg_details.id, 'pending', 'add')
                        db.session.add(approved_imei)
                    elif imei_object and imei_object.status == 'removed':
                        imei_object.status = 'pending'
                        imei_object.removed = False
                        imei_object.request_id = reg_details.id
                        db.session.add(imei_object)
            reg_details.update_processing_status('Processed')
            reg_details.update_report_status('Processing')
            db.session.commit()

            task_id = Utilities.generate_summary(flatten_imeis, reg_details.tracking_id)
            if task_id:
                Utilities.pool_summary_request(task_id, reg_details, app)
            else:
                reg_details.update_report_status('Failed')
                db.session.commit()
        except Exception:
            reg_details.update_processing_status('Failed')
            db.session.commit()
Beispiel #4
0
 def async_bulk_create(cls, reg_details, reg_device_id,
                       app):  # pragma: no cover
     """Create devices async."""
     with app.app_context():
         from app import db
         try:
             filename = reg_details.file
             tracking_id = reg_details.tracking_id
             args = {
                 'imei_per_device': reg_details.imei_per_device,
                 'device_count': reg_details.device_count
             }
             response = Utilities.process_reg_file(filename, tracking_id,
                                                   args)
             imeis = []
             for device_imeis in response:
                 tac = Utilities.get_imei_tac(device_imeis[0])
                 device = cls(tac, reg_details.id, reg_device_id)
                 db.session.add(device)
                 db.session.flush()
                 imeis = imeis + device_imeis
                 for imei in device_imeis:
                     imei_device = ImeiDevice(imei, device.id)
                     db.session.add(imei_device)
                     imei_object = ApprovedImeis.query.filter_by(
                         imei=imei[:14]).first()
                     if not imei_object:
                         approved_imei = ApprovedImeis(
                             imei[:14], reg_details.id, 'pending', 'add')
                         db.session.add(approved_imei)
                     elif imei_object and imei_object.status == 'removed':
                         imei_object.status = 'pending'
                         imei_object.removed = False
                         imei_object.request_id = reg_details.id
                         db.session.add(imei_object)
             db.session.commit()
             reg_details.update_processing_status('Processed')
             db.session.commit()
             task_id = Utilities.generate_summary(imeis,
                                                  reg_details.tracking_id)
             app.logger.info(
                 'task with task_id: {0} initiated'.format(task_id))
             if not task_id:
                 reg_details.update_report_status('Failed')
                 app.logger.info(
                     'task with task_id: {0} failed'.format(task_id))
                 db.session.commit()
             else:
                 Utilities.pool_summary_request(task_id, reg_details, app)
         except Exception as e:
             app.logger.exception(e)
             db.session.rollback()
             reg_details.update_report_status('Failed')
             reg_details.update_processing_status('Failed')
             db.session.commit()
             raise e