def get():

        kwargs = request.args
        try:
            USSDSchema().load(kwargs)
        except ValidationError as e:
            err = []
            for v in e.messages.values():
                err.append(v[0])

            return custom_text_response(
                err,
                status=STATUS_CODES.get('UNPROCESSABLE_ENTITY'),
                mimetype=MIME_TYPES.get('TEXT'))

        sms_text = kwargs['msg_text'].split(',')

        if len(sms_text) == 7:

            uid, serial_no, color, brand, model = sms_text[1], sms_text[
                2], sms_text[4], sms_text[5], sms_text[6]
            imeis = sms_text[3].split('|')

            params = {
                "uid": uid,
                "user_serial_no": serial_no,
                "user_imeis": imeis,
                "user_color": color,
                "user_brand": brand,
                "user_model": model
            }
            try:
                UserResponseSchema().load(params)
            except ValidationError as e:
                err = []
                for k, v in e.messages.items():
                    if k == "user_imeis" and isinstance(v, list):
                        err.append("Maximum 5 IMEIs per device is allowed")
                    elif k == "user_imeis" and isinstance(v, dict):
                        err.append("IMEI(s) format is not correct")
                    else:
                        err.append(v[0])

                return custom_text_response(
                    err,
                    status=STATUS_CODES.get('UNPROCESSABLE_ENTITY'),
                    mimetype=MIME_TYPES.get('TEXT'))

            ur = WebUserResponse()
            result = ur.user_response(params)
            return result
        else:
            return "USSD did not provide all the required 7 parameters"
    def post(**kwargs):
        """method to associate brands with OEM Logins."""

        try:
            q1 = OemLogins.query.filter(OemLogins.oem_name == '{}'.format(kwargs['login_name']),
                                        OemLogins.oem_id == '{}'.format(kwargs['login_id']),
                                        OemLogins.oem_status != 'deleted').first()
            if q1:

                associated_brands = [b.brand_name for b in BrandMapping.query.filter(BrandMapping.oem_id == '{}'.
                                                                          format(kwargs['login_id'])).all()]

                diff_brands = list(set(associated_brands) - set(kwargs['brands_list']))

                for b in diff_brands:
                    del_brand = BrandMapping.query.filter(BrandMapping.brand_name == b).first()
                    if del_brand:
                        del_brand.oem_id = None

                for b in kwargs['brands_list']:
                    q2 = BrandMapping.query.filter(BrandMapping.brand_name == '{}'.format(b)).first()

                    if q2:
                        q2.oem_id = q1.oem_id
                        q3 = OemResponse.query.filter(OemResponse.gsma_brand == '{}'.format(q2.brand_name)).all()

                        if q3:
                            for brand in q3:
                                brand.oem_id = q1.oem_id

                    else:
                        return custom_json_response(_("Brand name (%(b_name)s) is not found in DB", b_name=b),
                                                    STATUS_CODES.get('UNPROCESSABLE_ENTITY'), MIME_TYPES.get('JSON'))

                q1.oem_status = "approved"
                db.session.flush()
                db.session.commit()

            else:
                return custom_json_response(_("Login credentials are not correct"),
                                            STATUS_CODES.get('UNPROCESSABLE_ENTITY'), MIME_TYPES.get('JSON'))

            return custom_json_response(_("Brand(s) got successfully associated with OEM Login"),
                                            status=STATUS_CODES.get('OK'),
                                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(_("Error occurred while associating brands with OEM."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
Exemplo n.º 3
0
    def put(**kwargs):
        """method to get OEM's response for single IMEI."""

        try:
            all_imeis = []

            if kwargs['oem_imei'] in kwargs['oem_other_imeis']:
                return custom_json_response(
                    _("Every IMEI slot must have unique IMEI"),
                    STATUS_CODES.get('UNPROCESSABLE_ENTITY'),
                    MIME_TYPES.get('JSON'))

            chk_imei = OemResponse.query.filter(
                OemResponse.oem_imei == kwargs['oem_imei']).first()

            if chk_imei:

                chk_imei.oem_other_imeis = kwargs['oem_other_imeis']
                for imei in kwargs['oem_other_imeis']:
                    all_imeis.append(imei)
                all_imeis.append(kwargs['oem_imei'])

                chk_imei.oem_serial_no = kwargs['oem_serial_no'].strip()
                chk_imei.oem_color = kwargs['oem_color']
                chk_imei.oem_brand = kwargs['oem_brand']
                chk_imei.oem_model = kwargs['oem_model']
                chk_imei.oem_rat = kwargs['oem_rat']
                chk_imei.oem_mac = kwargs['oem_mac']
                chk_imei.oem_all_imeis = all_imeis
                chk_imei.oem_response_date = strftime("%Y-%m-%d %H:%M:%S")

                db.session.flush()
                db.session.commit()

                return custom_json_response(_("Response successfully updated"),
                                            STATUS_CODES.get('OK'),
                                            MIME_TYPES.get('JSON'))
            else:
                return custom_json_response(
                    _("IMEI is not correct"),
                    STATUS_CODES.get('UNPROCESSABLE_ENTITY'),
                    MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(_("Error occurred while fetching OEM response."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def get(**kwargs):
        """ Method to provide detailed Information of Duplication-List Table """

        try:
            total_count = 0
            oem_res = {"total_count": total_count, "oem_response": []}

            logins = db.session.query(OemLogins).all()
            login_dict = dict(
                (login.oem_id, login.oem_name) for login in logins).items()

            if kwargs['filter'] == "pending_imeis":

                total_count = OemResponse.query.filter(
                    OemResponse.oem_serial_no == None).count()
                oem_res["total_count"] = total_count

                pending_imeis = OemResponse.query.filter(OemResponse.oem_serial_no == None).order_by(OemResponse.id)\
                                                 .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = oem_row_formatter(pending_imeis, login_dict)

            elif kwargs['filter'] == "responded_imeis":

                total_count = OemResponse.query.filter(
                    OemResponse.oem_serial_no != None).count()
                oem_res["total_count"] = total_count

                responded_imeis = OemResponse.query.filter(OemResponse.oem_serial_no != None).order_by(OemResponse.id)\
                                                   .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = oem_row_formatter(responded_imeis, login_dict)

            else:
                return custom_json_response(
                    _("selected Filter is not applicable"),
                    STATUS_CODES.get('BAD_REQUEST'), MIME_TYPES.get('JSON'))

            oem_res["oem_response"] = oem_res["oem_response"] + search

            return Response(json.dumps(oem_res),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(_("Error occurred while retrieving OEM response."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def get():
        """method to provide all oem-logins along with their details"""

        oem_login = {"oem_logins": []}
        try:
            logins = OemLogins.query.filter(
                OemLogins.oem_status != 'deleted').all()

            if logins:
                oem_details = {}
                for l in logins:
                    oem_details['oem_name'] = l.oem_name
                    oem_details['oem_id'] = l.oem_id
                    oem_details['oem_status'] = l.oem_status

                    oem_login['oem_logins'].append(dict(oem_details))

            return Response(json.dumps(oem_login),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info("Error occurred while retrieving Login details.")
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
Exemplo n.º 6
0
    def get():
        """ Method to provide summary of users' response """

        try:

            oem_res = {"oem_response": []}
            login_dict = {}

            logins = db.session.query(OemResponse.oem_id).group_by(OemResponse.oem_id).all()

            for login in logins:
                qry = OemLogins.query.filter(OemLogins.oem_id == login[0]).first()

                if qry:
                    login_dict["oem"] = qry.oem_name
                else:
                    login_dict["oem"] = "unknown"

                login_dict["pending_imeis"], login_dict["responded_imeis"] = oem_counts(login[0])

                oem_res["oem_response"].append(dict(login_dict))

            return Response(json.dumps(oem_res), status=STATUS_CODES.get('OK'), mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(_("Error occurred while retrieving OEM response."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
Exemplo n.º 7
0
    def get(**kwargs):
        """method to get all IMEIs related to provided OEM whose response is pending."""

        try:

            imei_list = []
            chk_count = OemResponse.query.filter(
                OemResponse.oem_id == kwargs['login_id'],
                OemResponse.oem_serial_no == None).count()
            chk_imeis = OemResponse.query.filter(OemResponse.oem_id == kwargs['login_id'],
                                                 OemResponse.oem_serial_no == None).offset(kwargs['start'])\
                                                 .limit(kwargs['limit']).all()

            if chk_imeis:

                for c in chk_imeis:
                    imei_list.append(c.oem_imei)

            return Response(json.dumps({
                "IMEIs": imei_list,
                "count": chk_count
            }),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(_("Error occurred while fetching OEM IMEIs."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def get(**kwargs):
        """method to provide list of all unique Manufacturers from GSMA TAC DATA"""

        try:

            if kwargs['search']:
                brand_lowercase = (kwargs['search'].lower()).strip()
                chk_count = BrandMapping.query.filter(BrandMapping.brand_name.like('%{}%'.format(brand_lowercase))).\
                            count()
                search = [
                    b.brand_name for b in BrandMapping.query.filter(
                        BrandMapping.brand_name.like('%{}%'.format(
                            brand_lowercase))).offset(kwargs['start']).limit(
                                kwargs['limit']).all()
                ]

                return Response(json.dumps({
                    "search_result": search,
                    "count": chk_count
                }),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))
            else:
                chk_count = db.session.query(BrandMapping.brand_name).order_by(
                    BrandMapping.brand_name).count()
                brands = [
                    b.brand_name
                    for b in db.session.query(BrandMapping.brand_name).
                    order_by(BrandMapping.brand_name).offset(
                        kwargs['start']).limit(kwargs['limit']).all()
                ]

                return Response(json.dumps({
                    "brands_list": brands,
                    "count": chk_count
                }),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info("Error occurred while retrieving brands detail.")
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def user_response(kwargs):
        """Static method to extract User response via Web portal """

        try:

            chk_imei = DupList.query.filter(DupList.uid == kwargs['uid']).first()

            if chk_imei and chk_imei.imei in kwargs['user_imeis']:

                chk_uid = UserResponse.query.filter(UserResponse.uid == kwargs['uid'],
                                                    UserResponse.user_serial_no == None).first()
                if chk_uid:
                    chk_uid.user_serial_no = kwargs['user_serial_no'].strip()
                    chk_uid.user_color = kwargs['user_color']
                    chk_uid.user_brand = kwargs['user_brand']
                    chk_uid.user_model = kwargs['user_model']
                    chk_uid.user_imeis = kwargs['user_imeis']
                    chk_uid.user_response_date = strftime("%Y-%m-%d %H:%M:%S")

                    db.session.flush()
                    db.session.commit()

                    return custom_json_response(_("User Response successfully updated"),
                                                STATUS_CODES.get('OK'), MIME_TYPES.get('JSON'))
                else:
                    return custom_json_response(_("UID is not correct or already used"),
                                                STATUS_CODES.get('UNPROCESSABLE_ENTITY'), MIME_TYPES.get('JSON'))
            else:
                return custom_json_response(_("UID is not associated with any of the provided IMEIs"),
                                            STATUS_CODES.get('UNPROCESSABLE_ENTITY'), MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(_("Error occurred while fetching user response."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
Exemplo n.º 10
0
    def get():
        """ Method to provide summary of users' response """

        try:
            t = "user_summary"
            user_dict = {t: {}}
            user_dict[t]["pending_imeis"] = UserResponse.query.filter(UserResponse.user_serial_no == None).count()
            user_dict[t]["responded_imeis"] = UserResponse.query.filter(UserResponse.user_serial_no != None).count()

            return Response(json.dumps(user_dict), status=STATUS_CODES.get('OK'), mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info("Error occurred while retrieving OEM details.")
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def get():
        """ Method to provide statistics of uploaded duplication lists """

        try:
            tmp = "duplication_list_Stats"
            duplist_stat = {tmp: {}}

            duplist_stat[tmp]["total_imeis"] = DupList.query.filter().count()

            duplist_stat[tmp]["processed_imeis"] = DupList.query.filter(
                DupList.imei_status != None).count()

            duplist_stat[tmp]["pending_imeis"] = duplist_stat[tmp][
                "total_imeis"] - duplist_stat[tmp]["processed_imeis"]

            duplist_stat[tmp]["genuine_imeis"] = DupList.query.filter(
                DupList.imei_status == True).count()

            duplist_stat[tmp]["duplicated_imeis"] = DupList.query.filter(
                DupList.imei_status == False).count()

            duplist_stat[tmp]["sms_notified_imeis"] = DupList.query.filter(
                DupList.sms_notification == True).count()

            duplist_stat[tmp]["sms_awaited_imeis"] = DupList.query.filter(
                DupList.sms_notification == None).count()

            start_date = (datetime.today() -
                          timedelta(days=conf['threshold_days'])).date()
            duplist_stat[tmp]["threshold_crossed_imeis"] = DupList.query.filter(DupList.list_upload_date < start_date)\
                                                                        .count()

            return Response(json.dumps(duplist_stat),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(
                _("Error occurred while retrieving Duplication List detail."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
Exemplo n.º 12
0
    def get(**kwargs):
        """method to provide bulk-imeis for OEMs to download as a csv file."""

        try:
            tmp_dir = ''
            chk_login_detail = OemLogins.query.filter(OemLogins.oem_name == kwargs['login_name'],
                                                      OemLogins.oem_id == kwargs['login_id'],
                                                      OemLogins.oem_status != 'deleted').first()
            if chk_login_detail:
                imeis = [o.oem_imei for o in OemResponse.query.filter(OemResponse.oem_serial_no == None,
                                                                  OemResponse.oem_id == kwargs['login_id']).all()]
                try:

                    filename = "IMEI-List_" + kwargs['login_name'] + '_' + strftime("%Y-%m-%d_%H-%M-%S") + '.csv'
                    tmp_dir = tempfile.mkdtemp()
                    filepath = os.path.join(tmp_dir, filename)

                    with open(filepath, 'w') as file:
                        file.write('IMEI,Serial_no,Color,Brand,Model,RAT,MAC,Other_IMEIs\n')
                        file.write(',\n'.join(imeis))

                    file.close()

                    response = make_response(send_file(filepath, as_attachment=True))
                    response.headers['Cache-Control'] = 'no-store'
                    return response

                finally:
                    rmtree(tmp_dir)

            else:
                return custom_json_response(_("Login credentials are not matched"),
                                            status=STATUS_CODES.get('NOT_FOUND'),
                                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(_("Error occurred while downloading a file."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
Exemplo n.º 13
0
    def get(**kwargs):
        """method to get list of all associated brands with particular OEM Login."""

        try:
            brands = [
                b.brand_name for b in BrandMapping.query.filter(
                    BrandMapping.oem_id == '{}'.format(
                        kwargs['login_id'])).all()
            ]

            return Response(json.dumps({"Associated_brands": brands}),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info("Error occurred while retrieving summary.")
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def get():
        """method to get Dashboard Counts"""

        try:
            brand_count, approved_logins, pending_logins, total_tacs = dashboard_counts(
                "counters")

            return Response(json.dumps({
                "unique_brands": brand_count,
                "total_tacs": total_tacs,
                "approved_logins": approved_logins,
                "pending_logins": pending_logins
            }),
                            status=STATUS_CODES.get('OK'),
                            mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(
                "Error occurred while retrieving dashboard counts.")
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def get():
        """ Method to provide statistics of OEM Logins and related GSMA Brands """

        try:

            var1 = "oem_logins_detail"
            var2 = "gsma_brands_detail"
            oem_summary = {var1: {}, var2: {}}

            oem_summary[var2]["unique_brands"], oem_summary[var1]["approved_oems"], \
            oem_summary[var1]["pending_oems"], oem_summary[var2]["total_tacs"], \
            oem_summary[var1]["total_oems"], oem_summary[var1]["deleted_oems"], \
            oem_summary[var2]["associated_brands"], oem_summary[var2]["unassociated_brands"] \
            = dashboard_counts("summary")

            return Response(json.dumps(oem_summary), status=STATUS_CODES.get('OK'), mimetype=MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info("Error occurred while retrieving OEM details.")
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def get(**kwargs):
        """ Method to provide detailed Information of Duplication-List Table """

        try:

            if kwargs['filter'] == "pending_imeis":

                total_count = UserResponse.query.filter(
                    UserResponse.user_serial_no == None).count()

                qry = UserResponse.query.filter(UserResponse.user_serial_no == None).order_by(UserResponse.id)\
                                        .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = user_row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "responded_imeis":

                total_count = UserResponse.query.filter(
                    UserResponse.user_serial_no != None).count()

                qry = UserResponse.query.filter(UserResponse.user_serial_no != None).order_by(UserResponse.id)\
                                        .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = user_row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "genuine_imeis":

                total_count = UserResponse.query.filter(
                    UserResponse.uid_status == True).count()

                qry = UserResponse.query.filter(UserResponse.uid_status == True).order_by(UserResponse.id)\
                                        .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = user_row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "duplicated_imeis":

                total_count = UserResponse.query.filter(
                    UserResponse.uid_status == False).count()

                qry = UserResponse.query.filter(UserResponse.uid_status == False).order_by(UserResponse.id)\
                                        .offset(kwargs['start']).limit(kwargs['limit']).all()
                search = user_row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            else:
                return custom_json_response(
                    _("selected Filter is not applicable"),
                    STATUS_CODES.get('BAD_REQUEST'), MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(
                _("Error occurred while retrieving User response."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()
    def get(**kwargs):
        """ Method to provide detailed Information of Duplication-List Table """

        try:

            if kwargs['filter'] == "all_imeis":

                total_count = db.session.query(DupList).count()

                qry = [
                    d for d in db.session.query(DupList).order_by(DupList.id).
                    offset(kwargs['start']).limit(kwargs['limit']).all()
                ]

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "processed_imeis":

                total_count = DupList.query.filter(
                    DupList.imei_status != None).count()

                qry = DupList.query.filter(DupList.imei_status != None).order_by(DupList.id).offset(kwargs['start'])\
                                   .limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "pending_imeis":

                total_count = DupList.query.filter(
                    DupList.imei_status == None).count()

                qry = DupList.query.filter(DupList.imei_status == None).order_by(DupList.id).offset(kwargs['start']) \
                                   .limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "genuine_imeis":

                total_count = DupList.query.filter(
                    DupList.imei_status == True).count()

                qry = DupList.query.filter(DupList.imei_status == True).order_by(DupList.id).offset(kwargs['start']) \
                                   .limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "duplicated_imeis":

                total_count = DupList.query.filter(
                    DupList.imei_status == False).count()

                qry = DupList.query.filter(DupList.imei_status == False).order_by(DupList.id).offset(kwargs['start']) \
                                   .limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "sms_notified_imeis":

                total_count = DupList.query.filter(
                    DupList.sms_notification == True).count()

                qry = DupList.query.filter(DupList.sms_notification == True).order_by(DupList.id)\
                                   .offset(kwargs['start']).limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "sms_pending_imeis":

                total_count = DupList.query.filter(
                    DupList.sms_notification == None).count()

                qry = DupList.query.filter(DupList.sms_notification == None).order_by(DupList.id)\
                                   .offset(kwargs['start']).limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            elif kwargs['filter'] == "threshold_crossed_imeis":

                start_date = (datetime.today() -
                              timedelta(days=conf['threshold_days'])).date()

                total_count = DupList.query.filter(
                    DupList.list_upload_date < start_date).count()

                qry = DupList.query.filter(DupList.list_upload_date < start_date).order_by(DupList.id)\
                                   .offset(kwargs['start']).limit(kwargs['limit']).all()

                search = row_formatter(qry)
                search["total_count"] = total_count

                return Response(json.dumps(search),
                                status=STATUS_CODES.get('OK'),
                                mimetype=MIME_TYPES.get('JSON'))

            else:
                return custom_json_response(
                    _("selected Filter is not applicable"),
                    STATUS_CODES.get('BAD_REQUEST'), MIME_TYPES.get('JSON'))

        except Exception as e:
            app.logger.info(
                _("Error occurred while retrieving Duplication-List Details."))
            app.logger.exception(e)
            db.session.rollback()

        finally:
            db.session.close()